# bzoj3033 太鼓达人 欧拉回路

## 题目传送门

https://lydsy.com/JudgeOnline/problem.php?id=3033

## 题解

#include<bits/stdc++.h>

#define fec(i, x, y) (int i = head[x], y = g[i].to; i; i = g[i].ne, y = g[i].to)
#define dbg(...) fprintf(stderr, __VA_ARGS__)
#define File(x) freopen(#x".in", "r", stdin), freopen(#x".out", "w", stdout)
#define fi first
#define se second
#define pb push_back

template<typename A, typename B> inline char smax(A &a, const B &b) {return a < b ? a = b, 1 : 0;}
template<typename A, typename B> inline char smin(A &a, const B &b) {return b < a ? a = b, 1 : 0;}

typedef long long ll; typedef unsigned long long ull; typedef std::pair<int, int> pii;

template<typename I> inline void read(I &x) {
int f = 0, c;
while (!isdigit(c = getchar())) c == '-' ? f = 1 : 0;
x = c & 15;
while (isdigit(c = getchar())) x = (x << 1) + (x << 3) + (c & 15);
f ? x = -x : 0;
}

const int K = 11 + 2;
const int N = (1 << 11) + 7;

int n, k, cnt;
char ans[N];
bool vis[N << 1];

struct Edge { int to, ne; } g[N << 1]; int head[N], tot;
inline void addedge(int x, int y) { g[++tot].to = y, g[tot].ne = head[x], head[x] = tot; }

inline void dfs(int x) {
for fec(i, x, y) if (!vis[i]) {
vis[i] = 1;
dfs(y);
}
ans[++cnt] = x;
}

inline void work() {
for (int i = 0; i <= (n >> 1); ++i) addedge(i, (n >> 1) & ((i << 1) | 1)), addedge(i, (n >> 1) & (i << 1));
dfs(0);
//	dbg("cnt = %d\n", cnt);
printf("%d ", n + 1);
--cnt;
for (int i = 0; i < k; ++i) putchar('0' + ((ans[cnt] >> i) & 1));
--cnt;
while (cnt >= k) putchar('0' + (ans[cnt--] & 1));
puts("");
}

inline void init() {
n = (1 << k) - 1;
}

int main() {
#ifdef hzhkk
freopen("hkk.in", "r", stdin);
#endif
init();
work();
fclose(stdin), fclose(stdout);
return 0;
}

posted @ 2019-11-04 21:59  hankeke  阅读(146)  评论(0编辑  收藏  举报