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

bitset效率低点。。水果。。

Posted by sjyubowen at 2011-02-18 17:21:25 on Problem 2453
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <bitset>
using namespace std;

int main()
{
	int i, cnt, n;
	while (scanf("%d", &n), n)
	{
		bitset<32> b1(n);
		cnt = b1.count(); // 二进制位为1的个数
		for (i = n+1; ; i++)
		{
			bitset<32> b2(i);
			if (cnt == b2.count())
				break;
		}
		printf("%d\n", i);
	}
	return 0;
}

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