Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

STL bitset 水过

Posted by yousiki at 2016-07-31 10:11:28 on Problem 2183
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator