UVa 10038 Jolly Jumpers

一次AC !!! 太爽啦~

做法就不講了,我是用Algorithmist的作法,如下
http://www.algorithmist.com/index.php/UVa_10038

Set應用題,非常簡潔俐落的作法...虧我之前還在想一堆有的沒的。
bitset的速度也讓我驚豔, 0.008s ,相當的快!!

#include<iostream>
#include<bitset>
using namespace std;
#define MAXSIZE 3000
int main()
{
#ifndef ONLINE_JUDGE
freopen("10038.in", "r", stdin);
#endif
int length; //the length of sequence
int seq[MAXSIZE];
bitset<MAXSIZE> s;
//for each case
while ( scanf("%d ", &length) == 1 )
{
//read sequence
for (int i = 0; i < length; ++i)
scanf("%d ", &seq[i] );
if (length == 1)
{
puts("Jolly");
continue;
}
s.reset(); //init set
//add into set
for (int i = 1; i < length; ++i)
{
int diff = abs( seq[i] - seq[i - 1] );
if (diff > 0 && diff < length)
s.set(diff);
}
//judge
if ( s.count() == length - 1 )
puts("Jolly");
else
puts("Not jolly");
}
return 0;
}
view raw 10038.cpp hosted with ❤ by GitHub

留言

這個網誌中的熱門文章

UVa 10125 Sumsets

讀書心得: 撒哈拉的故事

讀書心得: 你以為你以為的就是你以為的嗎?