Description
Fight club is an organization where you release your pressure and emotion by fighting the other club members. The fight begins like this: n people standing in a circle. Then two adjacent guys are chosen to fight. The winner will stay and the loser will be sent to the hospital (there is no tie in the fighting). The cruel fight continues until there is only one left.
Input
First line contains integer T (T<=5), the number of test cases.
Output
For each test case, output n lines. If the ith fighter can be the survivor, output 1, otherwise output 0.
Sample Input
2 2 0 1 0 0 3 0 1 1 0 0 1 0 0 0
Sample Output
1 0 1 0 0 | ||
#include <stdio.h>
#include <cstring>
#include <set>
#include <iostream>
using namespace std;
bool cap[50][50]; //打败
bool overcome[50][50]; //相遇的可能性
int main(int argc, char const *argv[])
{
int n;
cin>>n;
while(n--)
{
int N;
cin>>N;
for (int i = 0; i <N; i++)
{
/* code */
for (int j=0;j<N;j++)
{
/* code */
cin>>cap[i][j];
}
}
for (int i = 0; i < N; ++i)
{
/* code */
overcome[i][0]=1;
overcome[i][1]=1;
for (int j=2;j <=N; ++j)
{
/* code */
overcome[i][j]=0;
}
}
for (int j=2;j<=N; ++j)
{
/* code */
for (int i = 0; i < N; ++i)
{
/* code */
for (int k=1;k<j;k++)// j 和k 都是长度,j为总长度,k为从1开始到j-1为止的宽度
{
/* code */
if(overcome[i][j]==0)
{
//cout<<overcome[i][k]<<" "<<overcome[(i+k)%N][(j-k)%N]<<" "<<cap[i][(i+k)%N]<<" "<<cap[(i+j)%N][(i+k)%N]<<endl;
overcome[i][j]=(overcome[i][k] && overcome[(i+k)%N][(j-k)%N])&&(cap[i][(i+k)%N]||cap[(i+j)%N][(i+k)%N]);
}
}
}
}
for (int i = 0; i < N; ++i)
{
cout<<overcome[i][N]<<endl;
/* code */
}
}
return 0;
}