2008-12-11
SRM416 Div1 Easy: NextNumber
今夜のSRMまで少し時間があるので過去問タイム。
本戦までTopCoder初挑戦の時に撃沈されたDIV2 500点問題(DIV1では250点)に再挑戦。
#include <vector>
#include <algorithm>
using namespace std;
#define all(c) (c).begin(),(c).end()
class NextNumber {
public:
int getNextNumber(int N) {
vector<int> v(32,0);
for (int n=31; n>0; n--) {
if (N == 0) break;
v[n] = N % 2;
N /= 2;
}
next_permutation(all(v));
int r = 0;
for (int i=0; i<32; i++) r = r*2 + v[i];
return r;
}
};
next_permutationを使って5分ちょいで解けてしまったw。システムテストも通った。
コメント
トラックバック - https://topcoder-g-hatena-ne-jp.jag-icpc.org/n4_t/20081211