天天看點

HDU 多校 6400 Parentheses Matrix(分情況構造)

HDU 多校 6400 Parentheses Matrix(分情況構造)
#include <bits/stdc++.h>
#define ll long long
#define rep(i, n) for (int i=0; i<(n); i++)
using namespace std;
int m, n;
bool rev;
char g[][];
int main()
{
    //freopen("D://rush.txt","r",stdin);
    //freopen("D://out.txt","w",stdout);
    int T; cin >> T;
    while (T--)
    {
        cin >> m >> n;
        memset(g, , sizeof g);
        rev = false;
        if (m & )
        {
            for(int i=;i<m;i++)
                for(int j=;j<n;j++)
                    g[i][j] = (j >= n/ ? ')' : '(');
        }
        else if (n & )
        {
            for(int i=;i<m;i++)
                for(int j=;j<n;j++)
                    g[i][j] = (i >= m/ ? ')' : '(');
        }
        else
        {
            if (m > n)
            {
                swap(m, n);
                rev = true;
            }
            if(m==)
                for(int i=;i<n;i++)
                {
                    g[][i] = '(';
                    g[][i] = ')';
                }
            else if(m==)
                for(int i=;i<n;i++)
                {
                    g[][i] = '(';
                    g[][i] = (i < n/ ? ')' : '(');
                    g[][i] = (i < n/ ? '(' : ')');
                    g[][i] = ')';
                }
            else
            {
                for(int i=;i<m;i++)
                    for(int j=;j<n;j++)
                    {
                        if (i ==  || j == ) g[i][j] = '(';
                        else if (i == m- || j == n-) g[i][j] = ')';
                        else if ((i^j)&) g[i][j] = ')';
                        else g[i][j] = '(';
                    }
            }
        }
        if (rev)
        {
            for(int j=;j<n;j++)
            {
                for(int i=;i<m;i++)
                    cout<<g[i][j];
                cout<<endl;
            }
        }
        else
        {
            for(int i=;i<m;i++)
            {
                for(int j=;j<n;j++)
                    cout<<g[i][j];
                cout<<endl;
            }
        }
    }
  return ;
}
           

繼續閱讀