Parentheses Matrix

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 0    Accepted Submission(s): 0
Special Judge

Problem Description
A parentheses matrix is a matrix where every element is either '(' or ')'. We define the goodness of a parentheses matrix as the number of balanced rows (from left to right) and columns (from up to down). Note that:

- an empty sequence is balanced;
- if A is balanced, then (A) is also balanced;
- if A and B are balanced, then AB is also balanced.

For example, the following parentheses matrix is a 2×4 matrix with goodness 3, because the second row, the second column and the fourth column are balanced:

)()(
()()

Now, give you the width and the height of the matrix, please construct a parentheses matrix with maximum goodness.

 
Input
The first line of input is a single integer T (1≤T≤50), the number of test cases.

Each test case is a single line of two integers h,w (1≤h,w≤200), the height and the width of the matrix, respectively.

 
Output
For each test case, display h lines, denoting the parentheses matrix you construct. Each line should contain exactly w characters, and each character should be either '(' or ')'. If multiple solutions exist, you may print any of them.
 
Sample Input
3
1 1
2 2
2 3
 
Sample Output
(
()
)(
(((
)))
 
 
 
构造题。找出每行每列最大匹配数的矩阵。
首先分奇偶性讨论。
1.奇奇情况为0,任意输出。
2.奇偶情况最大匹配为偶数值。
3.偶偶要分两种情况,最大匹配为max(h,w)+min(h,w)/2-1或h+w-4,
行和列较小的值若小于等于6,第一行(列)为“(”,最后一行(列)为“)”,大于6则第一行列全为“(”,最后一行列全为“)”。
其他的位置行列下标和若偶为“(”,奇为“)”。
 
 
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int MAX = ;
typedef long long LL; int main(void)
{
int t,n,m,i,j;
scanf("%d",&t);
while(t--){
scanf("%d%d",&n,&m);
if((n&)&&(m&)){
for(i=;i<=n;i++){
for(j=;j<=m;j++){
printf("(");
}
printf("\n");
}
}
else if(n&){
for(i=;i<=n;i++){
for(j=;j<=m;j++){
if(j&) printf("(");
else printf(")");
}
printf("\n");
}
}
else if(m&){
for(i=;i<=n;i++){
for(j=;j<=m;j++){
if(i&) printf("(");
else printf(")");
}
printf("\n");
}
}
else{
if(n>=m){
for(i=;i<=n;i++){
for(j=;j<=m;j++){
if(i==&&(m/-)>){
printf("(");
continue;
}
if(i==n&&(m/-)>){
printf(")");
continue;
}
if(j==){
printf("(");
continue;
}
if(j==m){
printf(")");
continue;
}
if((i+j)&){
printf(")");
}
else{
printf("(");
}
}
printf("\n");
}
}
else{
for(i=;i<=n;i++){
for(j=;j<=m;j++){
if(j==&&(n/-)>){
printf("(");
continue;
}
if(j==m&&(n/-)>){
printf(")");
continue;
}
if(i==){
printf("(");
continue;
}
if(i==n){
printf(")");
continue;
}
if((i+j)&){
printf(")");
}
else{
printf("(");
}
}
printf("\n");
}
}
}
}
return ;
}

HDU - 6400 多校8 Parentheses Matrix(构造)的更多相关文章

  1. hdu 6400 Parentheses Matrix

    题目链接 Problem Description A parentheses matrix is a matrix where every element is either '(' or ')'. ...

  2. hdu 2018多校8

    A.Character Encoding 简单计数 m个非负数和等于k的方案数为$\binom{m+k-1}{k}$, 但题目还要求每个数小于n, 容斥一下即可 即$ans = \sum\limits ...

  3. hdu多校第八场Parentheses Matrix

    #include<bits/stdc++.h> using namespace std; ][]; int main() { int t; scanf("%d",&am ...

  4. hdu 5015 233 Matrix(构造矩阵)

    http://acm.hdu.edu.cn/showproblem.php?pid=5015 由于是个二维的递推式,当时没有想到能够这样构造矩阵.从列上看,当前这一列都是由前一列递推得到.依据这一点来 ...

  5. HDU 4671 Backup Plan (2013多校7 1006题 构造)

    Backup Plan Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total ...

  6. HDU多校1003-Divide the Stones(构造)

    Problem Description There are n stones numbered from 1 to n.The weight of the i-th stone is i kilogr ...

  7. HDU 3213 Box Relations(拓扑排序构造)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3231 题意:有n个长方体,四种限制条件.(1)I x y x和y有相交:(2)X/Y/Z  x y x ...

  8. AGC027 D - Modulo Matrix 构造

    目录 题目链接 题解 代码 题目链接 AGC027 D - Modulo Matrix 题解 从第左上角第一个点开始染色,相邻不同色,染法唯一 那么一个点的四周与他不同色,我们另这个点比四周都大,那么 ...

  9. Educational Codeforces Round 48 (Rated for Div. 2) D 1016D Vasya And The Matrix (构造)

    D. Vasya And The Matrix time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

随机推荐

  1. SD相关的表

    [转] 一.客户主数据基本数据放在KNA1里:公司代码放在KNB1里:销售视图放在KNVV里:合作伙伴放在KNVP里:二.信用主数据KNKK里有信贷限额.应收总额.特别往来:S066里是未清订单值:S ...

  2. Java for LeetCode 111 Minimum Depth of Binary Tree

    Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shor ...

  3. Mac平台下的抓包神器 —— Charles

    在开发界,“抓包”这个词想必大家耳熟能详.通过抓包工具,能够获取设备在网络通讯过程中的交换数据包.在 Windows 平台上,笔者使用较多的是 Fiddler 工具,但是由于 Fiddle 使用 C# ...

  4. react-native修改android包名

    安卓已包名作为应用的唯一id,相对iOS来说改起来就不是那么方便,但为了能正式发布自己的应用,还是得改过来. 假设包名为com.exease.etd.objective,以下地方需要修改. 首先是两个 ...

  5. 蓝色科技AE宣传片头光晕视频

    蓝色科技AE宣传片头光晕视频素材,蓝色AE炫光素材,科技AE片头,精美,AE特效,绚丽,AE模板,视频素材,动画. 地址:http://www.huiyi8.com/xuanguang/ae/

  6. 分享知识-快乐自己:Struts2文件上传及文件下载

    1)Struts2单文件上传 action:类文件 package com.mlq.action; import com.opensymphony.xwork2.ActionSupport; impo ...

  7. ES索引瘦身 禁用_source后需要设置field store才能获取数据 否则无法显示搜索结果

    在默认情况下,开启_all和_source 这样索引下来,占用空间很大. 根据我们单位的情况,我觉得可以将需要的字段保存在_all中,然后使用IK分词以备查询,其余的字段,则不存储. 并且禁用_sou ...

  8. 一步完成MySQL向Redis迁移

    在把一个大表从 MySQL 迁移到 Redis 时,你可能会发现,每次提取.转换.导入一条数据是让人难以忍受的慢!这里有一个技巧,你可以通过使用管道把 MySQL 的输出直接输入到 redis-cli ...

  9. python基础-正则1

    什么是正则表达式? 正则表达式是一种小型的\高度专业化的变成语言,主要用于字符串处理 正则表达式是一种通用语言,在python中通过re模块实现,import re 工具:在线正则表达式测试 http ...

  10. 在eclipse创建Maven工程修改默认JRE

    1. 打开Maven安装目录的setting.xml文件 2.找到profiles标签 3.加入下面配置即可 <profile>    <id>jdk-1.8</id&g ...