A. Regular Bracket Sequences
题目如下:
A bracket sequence is a string containing only characters "(" and ")". A regular bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters "1" and "+" between the original characters of the sequence. For example, bracket sequences "()()" and "(())" are regular (the resulting expressions are: "(1)+(1)" and "((1+1)+1)"), and ")(", "(" and ")" are not.
You are given an integer n
. Your goal is to construct and print exactly n different regular bracket sequences of length 2n
.
Input
The first line contains one integer t
(1≤t≤50) — the number of test cases.
Each test case consists of one line containing one integer n
(1≤n≤50).
Output
For each test case, print n
lines, each containing a regular bracket sequence of length exactly 2n. All bracket sequences you output for a testcase should be different (though they may repeat in different test cases). If there are multiple answers, print any of them. It can be shown that it's always possible.
AC代码如下:
#include<stdio.h>
int main()
{int t;int n;scanf("%d", &t);while (t--){scanf("%d", &n);int tmp = n;int i;while (tmp--){for (i = 1; i <= tmp; i++){printf("(");}for (i = 1; i <= n - tmp; i++){printf("()");}for (i = 1; i <= tmp; i++){printf(")");}printf("\n");}}
}
代码解释:
核心————》找规律
:‘*’————》()单独排列
()里面加 *
(())里面+*
。。。。。。。。。。。。
按照这个规律我们就可以写代码了,如果仍不明白,请结合代码与文字再理解一下。
开学的第三天,努力努力——》我想打ACM!
A. Regular Bracket Sequences相关推荐
- Codeforces Beta Round #5 C. Longest Regular Bracket Sequence 栈/dp
C. Longest Regular Bracket Sequence Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.c ...
- CF思维联系– Codeforces-990C Bracket Sequences Concatenation Problem(括号匹配+模拟)
ACM思维题训练集合 A bracket sequence is a string containing only characters "(" and ")" ...
- Bracket Sequences Concatenation Problem括号序列拼接问题(栈+map+思维)
A bracket(括号) sequence is a string containing only characters "(" and ")".A regu ...
- 02.08 Longest Regular Bracket Sequence
最长的常规支架序列|断续器 (jxnu.edu.cn)https://acs.jxnu.edu.cn/problem/CF5C 描述: This is yet another problem deal ...
- Regular Bracket Sequence
题目描述: A bracket sequence is called regular if it is possible to obtain correct arithmetic expression ...
- 【CodeForces】CF26B Regular Bracket Sequence
题目地址: https://www.luogu.com.cn/problem/CF26B 题面翻译: 给出一个括号的序列,求最长的合法的子序列并输出. 原序列的长度≤106\le 10^6≤106 题 ...
- Educational Codeforces Round 4 C. Replace To Make Regular Bracket Sequence 栈
C. Replace To Make Regular Bracket Sequence 题目连接: http://www.codeforces.com/contest/612/problem/C De ...
- Codeforces 26B. Regular Bracket Sequence
Codeforces 26B. Regular Bracket Sequence 传送门:https://codeforces.com/problemset/problem/26/B 题目大意: 其实 ...
- 【Codeforces】CF 5 C Longest Regular Bracket Sequence(dp)
题目 传送门:QWQ 分析 洛谷题解里有一位大佬讲的很好. 就是先用栈预处理出可以匹配的左右括号在数组中设为1 其他为0 最后求一下最长连续1的数量. 代码 1 #include <bits/s ...
最新文章
- NDK 提示undefined reference to xxx“的解决办法
- linux命令行大全 笔记,分享|4 个 Linux 下的命令行笔记程序
- extern的关键字用法(C# 参考)
- Vue scoped CSS 与深度作用选择器 /deep/
- 个人JS体系整理(二)
- VTK:IO之GLTFExporter
- 加密解密_作业-加密解密程序
- centos 安装及vim使用
- 【实践】预训练模型在华为信息流推荐中的应用与探索.pdf(附下载链接)
- Spring Boot + JPA + Oracle 自增长字段实现示例
- Eclipse SVN插件Subclipse和Subversive简介
- JAVA远程读取服务器文件
- matlab 自写iradon,matlab的radon变换
- 用计算机怎么算斜边,斜边计算公式
- 雨课堂计算机网络答案,运行雨课堂进行网络综合布线实训教学
- GUI简介、AWT、Frame、Penal
- ios 视频选择封面功能
- Ubuntu18.04 操作分屏显示快捷键
- 矩阵分析与应用-05-向量空间、内积空间与线性映射02
- Switch NS 通过华硕梅林路由DNSMASQ屏蔽任天堂服务器
热门文章
- idea中git分支、合并与使用
- mui switch 实现方案 让你的html 设计更贴近原生
- C#LeetCode刷题之#507-完美数(Perfect Number)
- docker知识总结
- mac 设置终端样式_如何将终端样式设置为freeCodeCamp或任何您想要的样式
- php输入多少数值自动乘,报表数据填报中的自动计算
- 如何查看论坛付费隐藏_如何获取流量?这些引流方式你知多少?
- python+selenium 爬携程机票价格
- 协程-gevent(python版)
- 用Python标准库turtle画一只老虎,祝您新年虎虎生威,大吉大利