85pts求助!!!
  • 板块学术版
  • 楼主vincent_one
  • 当前回复5
  • 已保存回复5
  • 发布时间2023/8/19 19:52
  • 上次更新2023/11/3 02:36:02
查看原帖
85pts求助!!!
302008
vincent_one楼主2023/8/19 19:52

题目传送门P5657

评测记录

代码:

#include <bits/stdc++.h>
#define ull unsigned long long
using namespace std;
int n; ull k;
string s = "";
void Gray(ull x, int N) {
	if (N == 1) {
		s += (x == 0) ? '0' : '1';
		return;
	}
	if (x >= pow(2, N - 1)) {
		s += '1'; Gray(pow(2, N) - x - 1, N - 1);
	} else {
		s += '0'; Gray(x, N - 1);
	}
}
int main(void) {
	cin >> n >> k;
	Gray(k, n);
	cout << s << '\n';
	return 0;
}
2023/8/19 19:52
加载中...