2018 Multi-University Training Contest 8 hdu 6400 Parentheses Matrix

http://acm.hdu.edu.cn/showproblem.php?pid=6400

 

构造。

边长为奇*奇 奇*偶的就不说了

关键是偶*偶的。

一开始的想法是

()()()()

(()()())这样类似的循环。

那么答案就 max(a,b)+(min(a,b)-2)/2

4 6的话就是 6+(4-2)/2=7 

果断wa了

于是就在想:我这种方案是保证较长边的那些列/排都符合条件,然后让另一边的列/排尽量符合条件.

这可能不是最优的.  后来就想了如果能够破坏某一些符合条件的是不是能够让另一边的符合条件的数量加一些这样会更多

于是:

((((((((

()()()()

(()()())

()()()()

(()()())

()()()()

(()()())

)))))))) 这样是8*8  那么按照我那个答案应该算出来是11 但是这种的话就是6+6=8+8-4=12了 更多。

所以就是如果边长都是大于4的就可以用上面这种,一旦有一边小于等于4就用我那种

 

#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#include<cstdio>
using namespace std;
int T, x, y;
char mp[220][220];
int main()
{
    scanf("%d", &T);
    while (T--)
    {
        cin>>x>>y;
        if(x%2==1&&y%2==1)
        {
           for(int i=1;i<=x;i++)    
           {
               for(int j=1;j<=y;j++)
               {
                   cout<<"(";
               }
               cout<<endl;
           }
        }
        else if(x%2==1)
        {
            for(int i=1;i<=x;i++)
            {
                for(int j=1;j<=y;j++)
                {
                    if(j%2==1)
                    cout<<"(";
                    else cout<<")";
                }
                cout<<endl;
            }
        }
        else if(y%2==1)
        {
            for(int i=1;i<=x;i++)
            {
                for(int j=1;j<=y;j++)
                {
                    if(i%2==1)
                    {
                        cout<<"(";
                    }
                    else cout<<")";
                }
                cout<<endl;
            }
        }
        else if(x<6||y<6){
            if(x<y)
            {
                for(int j=1;j<=y;j+=2)
                {
                    for(int i=1;i<=x;i++)
                    {
                        if(i%2==1)
                        {
                            mp[i][j]='(';
                        }
                        else mp[i][j]=')';
                    }
                }
                for(int j=2;j<=y;j+=2)
                {
                    mp[1][j]='(';
                    mp[x][j]=')';
                    for(int i=2;i<=x-1;i++)
                    {
                        if(i%2==1)
                        {
                            mp[i][j]=')';
                        }
                        else mp[i][j]='(';
                    }
                }
                for(int i=1;i<=x;i++)
                {
                    for(int j=1;j<=y;j++)
                    cout<<mp[i][j];
                    cout<<endl;
                }
            }
            else{
                for(int i=1;i<=x;i++)
                {
                    if(i%2==1)
                    {
                        for(int j=1;j<=y;j++)
                        {
                            if(j%2==1)
                            cout<<"(";
                            else cout<<")";
                        }
                        cout<<endl;
                    }
                    else{
                        cout<<"(";
                        for(int j=2;j<=y-1;j++)
                        {
                            if(j%2==1)
                            {
                                cout<<")";
                            }
                            else cout<<"(";
                        }
                        cout<<")";
                        cout<<endl;
                    }
                }
            }
        }
        else {
                for(int j=1;j<=y-1;j++)
                cout<<"(";
                cout<<")"<<endl;
                for(int i=1;i<=x-2;i++)
                {
                    if(i%2==1)
                    {
                        for(int j=1;j<=y;j++)
                        {
                            if(j%2==1)
                            cout<<"(";
                            else cout<<")";
                        }
                    }
                    else{
                        cout<<"(";
                        for(int j=2;j<=y-1;j++)
                        {
                            if(j%2==0)
                            {
                                cout<<"(";
                            }
                            else cout<<")";
                        }
                        cout<<")";
                    }
                    cout<<endl;
                }
                cout<<"(";
                for(int i=1;i<=y-1;i++)
                cout<<")";
                cout<<endl;
        }
    }
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值