fight club

15 篇文章 0 订阅
     
 
Time Limit: 1sec    Memory Limit:32MB
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.
It is somewhat strange to see that when two guys fight each other, the result is always definite, and you know the result of every pair of fighters. Though they enjoy fighting, they still want to be the winner. You are to tell each of them, if the fight is arranged properly, can he be the winner.

Input

First line contains integer T (T<=5), the number of test cases.
For each test case, the first line contains n (1<=n<=40), the number of people. Following is the description of a n*n matrix A. Following n lines each contains n ‘0’ or ‘1’, separated by a single blank. The ith number in jth line indicates the fighting result of ith and jth fighter. If it is ‘1’, then the ith fighter will always beat the jth fighter, otherwise he will always lose. You can safely assume that aij and aji are different and aii=0 for every distinct i and j.
The people are numbered counterclockwise. 

Output

For each test case, output n lines. If the ith fighter can be the survivor, output 1, otherwise output 0.
Output a blank line after each test case. 

Sample Input
 Copy sample input to clipboard
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;
}
                           


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值