题解 | #Ternary String#

Ternary String

https://ac.nowcoder.com/acm/contest/20325/A

D题偶然发现,这个奇数不行,偶数可以,并且都能从上一个可以的情况推出来,可以把答案从n=2开始,然后上面放1下边放-1,然后再调两边,最后看成两个三角形,以对角线为分界线,上面全是1,下面全是-1,对角线上,前n/2行是1,后是0.

#include <iostream>
#include <algorithm>
#include <map>
#include <string>
#include <cstring>
#include <cmath>
#include <stack>
#include<bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
#define ll long long
#define fast ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define sc(a) scanf("%lld",&a)
#define pf(a) printf("%d",a) 
#define endl "\n"
#define int long long
#define mem(a,b) memset(a,b,sizeof a)
#define ull unsigned long long
#define INF 0x3f3f3f3f3f3f3f3f
#define inf 0x3f3f3f3f
#define rep(i,a,b) for(auto i=a;i<=b;++i)
#define bep(i,a,b) for(auto i=a;i>=b;--i)
#define lowbit(x) x&(-x)
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define PI acos(-1)
#define pb push_back
#define x first
#define y second
const double eps = 1e-6;
const int mod = 998244353;
const int MOD = 1e9 + 7;

signed main()
{
	int n, t;
	sc(t);
	while(t--)
	{
		sc(n);
		if(n&1) cout<<"impossible"<<endl;
		else
		{
			cout<<"possible"<<endl;
			for(int i=1;i<=n;++i)
			{
				for(int j=1;j<=n-i;++j)
				{
					cout<<1<<' ';
				}
				if(i>n/2) cout<<0<<' ';
				else cout<<1<<' ';
				for(int j=1;j<i;j++) cout<<-1<<' ';
				cout<<endl;
			}
		}
	}
	return 0;
}
全部评论

相关推荐

今天投了小鹏,收到了AI面,大概会问哪些啊?
期末一定及格:总共4个部分,心理测评、行测、然后就是问岗位、对岗位的理解、过往遇到了哪些难点怎么解决,很简单,没有什么特别专业的问题,都是一些综合素质相关的
小鹏汽车AI面4人在聊
点赞 评论 收藏
分享
牛客83700679...:简历抄别人的,然后再投,有反馈就是简历不行,没反馈就是学历不行,多投多改只要技术不差机会总会有的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务