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;
}
上一篇:【Django】基于djangorestframework序列化的添加自定义返回字段


下一篇:【POJ - 1082】Calendar Game(简单博弈)