Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
STL bitset 水过#include<bitset> #include<cstdio> #include<cstring> #include<cstdlib> #include<iostream> #include<algorithm> using namespace std; /* POJ 2183 */ const int N = 1000005; bitset<N> vis; signed main(void) { /* input */ int integer; scanf("%d", &integer); /* prepare */ int step = 0, length = 0; /* calculate */ while (!vis[integer]) { vis.set(integer); int mid = 0; mid += ((integer % 100000) / 10000) * 1000; mid += ((integer % 10000) / 1000) * 100; mid += ((integer % 1000) / 100) * 10; mid += ((integer % 100) / 10) * 1; mid *= mid; integer = mid % 1000000; step++; } vis.reset(); while (!vis[integer]) { vis.set(integer); int mid = 0; mid += ((integer % 100000) / 10000) * 1000; mid += ((integer % 10000) / 1000) * 100; mid += ((integer % 1000) / 100) * 10; mid += ((integer % 100) / 10) * 1; mid *= mid; integer = mid % 1000000; length++; } /* output */ printf("%d %d %d\n", integer, length, step); #ifndef ONLINE_JUDGE system("pause"); #endif //!ONLINE_JUDGE } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator