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 ...
随机推荐
- Lodop打印控件设置表格次页偏移
Lodop打印控件有很好的自动分页功能,超文本table表格一页装不下,自动分到第二页,第三页……通常表格之前还会有一些内容,比如标题,制表人名称日期什么的杂七杂八的东西,这种东西会占用一定的空间,这 ...
- Lodop纯文本英文-等符号自动换行问题
ADD_PRINT_TEXT纯文本,宽度不够,高度足够,超宽会自动换行,高度不够会隐藏后面的内容.在超宽自动换行的时候,如果有-或()之类的,英文单词不拆分,或其他一些认为是不拆分的情况,会造成还没有 ...
- ASP.NET Core Building chat room using WebSocket
Creating “Login form” We use here simple form where user can insert his or her preferred nick name f ...
- kubernetes 创建系统用户来支持访问 dashboard
Dashboard: 1.部署: 下载yaml文件 可以直接运行也可以下载下来kubectl apply -f https://raw.githubusercontent.com/kubernete ...
- mysql 测试php连接问题
<?php$servername = "shuhua.dbhost";$username = "shuhua_user";$password = &quo ...
- 在 Activity 中实现 getContentView 操作
2017/9/8 17:17:03 前言 最近接到个需要优化Android原生系统设置APK的任务.这个任务里面有一个更换应用背景图片的需求.我手里的这个设备是一个平板设备,使用了一下这个 ...
- Android学习第6天
创建一个新的activity 四大组件需要在清单文件中配置 可在清单文件中配置多个启动图标过单个启动图标 Activity下的lable和icon属性可以和Application节点的属性不一样,默认 ...
- Sudoku POJ - 3076
Sudoku Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 5769 Accepted: 2684 Descripti ...
- Tournament ZOJ - 4063 (青岛区域赛 F 打表)
打表题.. 规律是找出来了 奈何优化不了 .... #include <iostream> #include <cstdio> #include <sstream> ...
- THUWC2018游记
前言 这次THUWC有pretest,非常不错.但还是要对拍. DAY1 上午先去报个到. 下午1:30开始比赛,状态还是很好的. 开场先看题. 发现t1是个联赛贪心题,就花了半个小时写完+拍完了. ...