UVa 10038 Jolly Jumpers
一次AC !!! 太爽啦~
做法就不講了,我是用Algorithmist的作法,如下
http://www.algorithmist.com/index.php/UVa_10038
Set應用題,非常簡潔俐落的作法...虧我之前還在想一堆有的沒的。
bitset的速度也讓我驚豔, 0.008s ,相當的快!!
做法就不講了,我是用Algorithmist的作法,如下
http://www.algorithmist.com/index.php/UVa_10038
Set應用題,非常簡潔俐落的作法...虧我之前還在想一堆有的沒的。
bitset的速度也讓我驚豔, 0.008s ,相當的快!!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |
留言
張貼留言