PO1068 Parencodings 模拟题
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 28860 | Accepted: 16997 |
Description
q By an integer sequence P = p1 p2...pn where pi is the number of left parentheses before the ith right parenthesis in S (P-sequence).
q By an integer sequence W = w1 w2...wn where for each right parenthesis, say a in S, we associate an integer which is the number of right parentheses counting from the matched left parenthesis of a up to a. (W-sequence).
Following is an example of the above encodings:
S (((()()())))
P-sequence 4 5 6666
W-sequence 1 1 1456
Write a program to convert P-sequence of a well-formed string to the W-sequence of the same string.
Input
Output
Sample Input
2
6
4 5 6 6 6 6
9
4 6 6 6 6 8 9 9 9
Sample Output
1 1 1 4 5 6
1 1 2 4 5 1 1 3 9 从别人的博客上学的:
https://www.cnblogs.com/--ZHIYUAN/p/5910981.html
#include<iostream>
#include<string>
#include<cstdio>
using namespace std;
int main(){
int n,T;
scanf("%d",&T);
while(T--){
int q1,q2 = ;
string s;
scanf("%d",&n);
for(int i = ; i < n; i++){
scanf("%d",&q1);
q2 = q1 - q2;
while(q2--)
s += "(";
s += ")";
q2 = q1;
}
int num = s.length();
int cnt = ;
int sum;
for(int i = ; i < num; i++){
if(s[i] == ')'){
cnt++;
int flag = ;
sum = ;
for(int j = i - ; j >= ; j--){
if(flag == )
break;
if(s[j] == ')'){
flag += ;
}
else if(s[j] == '('){
flag -= ;
sum++;
}
}
if(cnt != n)
printf("%d ",sum);
else
printf("%d\n",sum);
} }
}
return ;
}
PO1068 Parencodings 模拟题的更多相关文章
- poj 1068 Parencodings 模拟题
Description Let S = s1 s2...s2n be a well-formed string of parentheses. S can be encoded in two diff ...
- poj 1008:Maya Calendar(模拟题,玛雅日历转换)
Maya Calendar Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 64795 Accepted: 19978 D ...
- poj 1888 Crossword Answers 模拟题
Crossword Answers Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 869 Accepted: 405 D ...
- CodeForces - 427B (模拟题)
Prison Transfer Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u Sub ...
- sdut 2162:The Android University ACM Team Selection Contest(第二届山东省省赛原题,模拟题)
The Android University ACM Team Selection Contest Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里 ...
- 全国信息学奥林匹克联赛 ( NOIP2014) 复赛 模拟题 Day1 长乐一中
题目名称 正确答案 序列问题 长途旅行 英文名称 answer sequence travel 输入文件名 answer.in sequence.in travel.in 输出文件名 answer. ...
- UVALive 4222 Dance 模拟题
Dance 题目连接: https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&pag ...
- cdoj 25 点球大战(penalty) 模拟题
点球大战(penalty) Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/problem/show/2 ...
- Educational Codeforces Round 2 A. Extract Numbers 模拟题
A. Extract Numbers Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/600/pr ...
随机推荐
- change safari user agent
defaults write com.apple.safari customuseragent '"mozilla/5.0 (iphone; cpu iphone os 8_1 like m ...
- How to blog on Github
git clone https://github.com/test/test.github.io.git cd ~/test.github.io git config --global push.de ...
- Auth模块使用方法大全
auth认证 导包 from django.contrib import auth 默认数据库中使用auth_user表 创建超级用户 python manage.py createsuperuser ...
- python3.7之12306抢票脚本实现
悲催的12306,彻底沦为各路抢票软件的服务提供方.元旦伊始,纯粹12306官网及APP抢票,愈一周的时间,仅到手一张凌晨3:55回家的站票.为远离脑残,无奈选择抢票软件,预购年后返沪车票.BTW,研 ...
- python字符编码与文件打开
一 字符编码 储备知识点: 1.计算机系统分为三层: 应用程序 操作系统 计算机硬件 2.运行Python程序的三个步骤 1.先启动python解释器 2.再将python文件当做普通的文本文件读入内 ...
- Android app下载并安装
1 下载功能 //下载apk private void downloadApk(String apkUrl) throws PackageManager.NameNotFoundException ...
- 【XSY2716】营养餐 博弈论
题目描述 给你一棵有根树,每个点有两个属性\(a,b\) 两人轮流操作,每次要减小一个点的\(a\)值,要求 \[ a_x\geq\sum_{i\in child(x)}a_ib_i \] 保证初始状 ...
- Xadmin 组件基础使用以及全局配置
xadmin 的安装 方式一 pip 安装 会因为编码问题导致报错 因此需要下载 更改 README.rst 后本地安装 详情点击这里 方式二 源码方式安装 在 github 上下载源码后 将 xad ...
- MT【272】更大的视野,更好的思路.
已知$f(x)=\sum\limits_{k=1}^{2017}\dfrac{\cos kx}{\cos^k x},$则$f(\dfrac{\pi}{2018})=$_____ 分析:设$g(x)=\ ...
- 自定义Qt构建步骤,添加数据文件(txt,json等)到构建目录
Qt的qrc资源文件是只读的,因此我们如果要用txt之类的文件存储数据,在程序运行过程中就不能对它们进行修改,也就是不能进行读操作.用"file.open(QIODevice::WriteO ...