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 |
bitset效率低点。。水果。。#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator