HDU 多校 6400 Parentheses Matrix(构造)
Posted Harris-H
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了HDU 多校 6400 Parentheses Matrix(构造)相关的知识,希望对你有一定的参考价值。
HDU 多校 6400 Parentheses Matrix(构造)
// Problem: D. Parentheses Matrix
// Contest: Codeforces - 2018 Chinese Multi-University Training, Nanjing U Contest
// URL: https://codeforces.ml/gym/102192/problem/D
// Memory Limit: 128 MB
// Time Limit: 1000 ms
// Date: 2021-11-29 19:27:17
// --------by Herio--------
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N=1e3+5,M=2e4+5,inf=0x3f3f3f3f,mod=1e9+7;
const int hashmod[4] = 402653189,805306457,1610612741,998244353;
#define mst(a,b) memset(a,b,sizeof a)
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define x first
#define y second
#define pb emplace_back
#define SZ(a) (int)a.size()
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define per(i,a,b) for(int i=a;i>=b;--i)
#define ios ios::sync_with_stdio(false),cin.tie(nullptr)
void Print(int *a,int n)
for(int i=1;i<n;i++)
printf("%d ",a[i]);
printf("%d\\n",a[n]);
template <typename T> //x=max(x,y) x=min(x,y)
void cmx(T &x,T y)
if(x<y) x=y;
template <typename T>
void cmn(T &x,T y)
if(x>y) x=y;
char a[N][N];
int main()
int t;cin>>t;
while(t--)
int n,m;cin>>n>>m;
if( (n%2==1) && (m%2==1) )
rep(i,1,n)
rep(j,1,m) putchar('(');
putchar('\\n');
continue;
else if( (m%2==1) )
rep(i,1,n)
if(i&1) rep(j,1,m) putchar('(');
else rep(j,1,m) putchar(')');
putchar('\\n');
else if( (n%2==1) )
rep(i,1,n)
rep(j,1,m) putchar(j&1?'(':')');
putchar('\\n');
else
bool rev = 0;
if(n > m) swap(n,m),rev = true;
if( n == 2)
rep(i,1,m) a[1][i]='(',a[2][i]=')';
else if(n==4)
rep(i,1,n)
rep(j,1,m/2) a[i][j]=i&1?'(':')';
rep(j,m/2+1,m) a[i][j]=i<=n/2?'(':')';
else
rep(i,1,n)
rep(j,1,m)
if(i==1||j==1) a[i][j]='(';
else if(i==n||j==m) a[i][j]=')';
else if((i+j)&1) a[i][j]='(';
else a[i][j]=')';
if(rev)
//printf("n=%d m=%d\\n",n,m);
rep(i,1,m)
rep(j,1,n) putchar(a[j][i]);
putchar('\\n');
else
//printf("n=%d m=%d\\n",n,m);
rep(i,1,n)
rep(j,1,m) putchar(a[i][j]);
putchar('\\n');
return 0;
以上是关于HDU 多校 6400 Parentheses Matrix(构造)的主要内容,如果未能解决你的问题,请参考以下文章
[hud-6799] Parentheses Matching 构造 括号匹配 2020多校3