Codeforces

1.题目引入:

A chess tournament will be held soon, where nn chess players will take part. Every participant will play one game against every other participant. Each game ends in either a win for one player and a loss for another player, or a draw for both players.

Each of the players has their own expectations about the tournament, they can be one of two types:

  1. a player wants not to lose any game (i. e. finish the tournament with zero losses);
  2. a player wants to win at least one game.

You have to determine if there exists an outcome for all the matches such that all the players meet their expectations. If there are several possible outcomes, print any of them. If there are none, report that it's impossible.

Input

The first line contains a single integer tt (1≤t≤2001≤t≤200) — the number of test cases.

The first line of each test case contains one integer nn (2≤n≤502≤n≤50) — the number of chess players.

The second line contains the string ss (|s|=n|s|=n; si∈{1,2}si∈{1,2}). If si=1si=1, then the ii-th player has expectations of the first type, otherwise of the second type.

Output

For each test case, print the answer in the following format:

In the first line, print NO if it is impossible to meet the expectations of all players.

Otherwise, print YES, and the matrix of size n×nn×n in the next nn lines.

The matrix element in the ii-th row and jj-th column should be equal to:

  • +, if the ii-th player won in a game against the jj-th player;
  • -, if the ii-th player lost in a game against the jj-th player;
  • =, if the ii-th and jj-th players' game resulted in a draw;
  • X, if i=ji=j.

2.样例输出: 

Example

Input

3
3
111
2
21
4
2122

Output

YES
X==
=X=
==X
NO
YES
X--+
+X++
+-X-
--+X

3.代码如下: 

#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
using namespace std;
typedef long long ll;
const int maxn=201;
ll q[maxn][maxn],e[maxn];
ll t,n,m;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);  cout.tie(0);
	ll i,j,k;
	string p;
	cin>>t;
	while(t--)
	{
		cin>>n>>p;
		for(i=n;i>=1;i--) // 这一步是对下标的右移 
		{
			p[i]=p[i-1];
		}
		ll n2=0;  // 初始化 n2 为 0 
		for(i=1;i<=n;i++) if(p[i]=='2') n2++;  // 因为字符串中字符只有 1 ,2两种情况 
		//因为有两种情况即: 1.玩家一场都不输 2.一个玩家至少赢一场 
		if(n2==1||n2==2)    
		{
			printf("NO\n");
			continue;
		}
		//否则输出 YES 
		printf("YES\n");
		for(i=1;i<=n;i++) // 初始化 
		{
			for(j=1;j<=n;j++) q[i][j]=-5;
		}
		for(i=1;i<=n;i++)  // 当行和列下标相等时初始化为 2即可 
		{
			q[i][i]=2;
		}
		for(i=1;i<=n;i++) e[i]=1;  //起标记作用 是否已经被访问 
		for(i=1;i<=n;i++)
		{
			if(p[i]=='1')  
			{
				for(j=1;j<=n;j++)
				{
					q[i][j]=0;
					q[j][i]=0;
				}
			}
		}	
		for(i=1;i<=n;i++)
		{
			for(j=1;j<=n;j++)
			{
				if(q[i][j]==-5&&e[i]&&p[i]=='2') //如果没有被访问过且未被赋值 
				{
					e[i]=0;
					q[i][j]=1;
					q[j][i]=-1;
				}
			}
		}
		for(i=1;i<=n;i++)
		{
			for(j=1;j<=n;j++)
			{
				if(q[i][j]==-5) q[i][j]=0;  //如果已经全部访问但依然没赋值这 
			}
		}	
		for(i=1;i<=n;i++) q[i][i]=2;
		for(i=1;i<=n;i++)
		{
			for(j=1;j<=n;j++)
			{
				if(q[i][j]==-1)
				{
					cout<<"-";
				} 
				if(q[i][j]==0) 
				{
					cout<<"=";
				}
				if(q[i][j]==1) 
				{
					cout<<"+";
				}
				if(q[i][j]==2) 
				{
					cout<<"X";
				}
			}
			cout<<"\n";
		}	
	}
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

风遥~

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值