War of Inazuma (Easy Version)
题目链接:
https://ac.nowcoder.com/acm/contest/11261/H
题目描述:
As a traveler, you once witnessed the war of Inazuma, of which sides are the resistance and the Shogun’s army.
The map of Inazuma can be viewed as a unit n-dimensional hypercube, which has exactly 2^n vertices. Each vertex is labeled with an integer from 0 to 2^n - 1. Two vertices are adjacent if and only if there exists exactly one different bit in their nn-bit binary representation.
In the war of Inazuma, some vertices were occupied by the resistance army, and others were occupied by the Shogun’s Army. You also noticed that for each vertex u, the number of vertices adjacent to u and occupied by the same side as uu was no more than ⌈ sqrt n ⌉.
Many years later, you have already forgotten details of the war. Can you construct a hypercube satisfying all the above requirements?
输入描述:
The only line contains a single integer n(1≤n≤22).
输出描述:
Output a 01-string of length 2^n . The a1…an-th bit describes which side is vertex (a1,…,an) occupied by, 0 for the resistance army and 1 for the Shogun’s army. Here a1…an is an n-bit binary representation. Any answer satisfying all requirements will be accepted.
示例1:
输入
2
输出
0111
代码如下:
#include<iostream>
using namespace std;
int main(){
int n;
cin>>n;
for(int i=0;i<(1<<n);i++)
cout<<(__builtin_popcount(i)&1); //返回输入数据二进制中1的个数
return 0;
}