POJ1068 Parencodings(模拟)
题目链接。
分析:
水题。
#include <iostream>
#include <cstdio>
#include <cstring> using namespace std; const int maxn = ; int P[maxn], W[maxn];
char s[maxn]; int main(){
int T, n, m; scanf("%d", &T); while(T--) {
scanf("%d", &n);
P[] = ;
for(int i=; i<=n; i++) scanf("%d", &P[i]); //通过P推s
int cn = ;
for(int i=; i<=n; i++) {
for(int j=; j<P[i]-P[i-]; j++) {
s[cn++] = '(';
}
s[cn++] = ')';
}
s[cn++] = '\0'; //通过s推W
int rp_cnt = , lp_cnt, t, ls_cnt; for(int i=; i<cn; i++) {
if(s[i] == ')') {
rp_cnt++;
lp_cnt = t = ls_cnt = ;
for(int j=i; j>=; j--) {
if(s[j] == ')') { t++; ls_cnt++; }
else if(s[j] == '(') lp_cnt++;
if(lp_cnt == ls_cnt) break;
}
W[rp_cnt] = t;
}
} for(int i=; i<=n; i++) {
if(i != n) printf("%d ", W[i]);
else printf("%d\n", W[i]);
}
} return ;
}
POJ1068 Parencodings(模拟)的更多相关文章
- [POJ1068]Parencodings
[POJ1068]Parencodings 试题描述 Let S = s1 s2...s2n be a well-formed string of parentheses. S can be enco ...
- [ACM_模拟] POJ1068 Parencodings (两种括号编码转化 规律 模拟)
Description Let S = s1 s2...s2n be a well-formed string of parentheses. S can be encoded in two diff ...
- POJ1068——Parencodings
Parencodings Description Let S = s1 s2...s2n be a well-formed string of parentheses. S can be encode ...
- [poj1068]Parencodings_模拟
Parencodings 题目大意:给你一个P序列,表示从左到右的右括号左边有多少左括号,求M序列. 注释:M序列定义为每一个右括号左边最近的没有被之前的右括号匹配的括号之间,有多少已经匹配的括号队对 ...
- PO1068 Parencodings 模拟题
Parencodings Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 28860 Accepted: 16997 De ...
- Hdu1361&&Poj1068 Parencodings 2017-01-18 17:17 45人阅读 评论(0) 收藏
Parencodings Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total ...
- [ACM] POJ 1068 Parencodings(模拟)
Parencodings Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 19352 Accepted: 11675 De ...
- POJ 1068 Parencodings 模拟 难度:0
http://poj.org/problem?id=1068 #include<cstdio> #include <cstring> using namespace std; ...
- poj 1068 Parencodings 模拟
进入每个' ) '多少前' ( ', 我们力求在每' ) '多少前' ) ', 我的方法是最原始的图还原出来,去寻找')'. 用. . #include<stdio.h> #incl ...
随机推荐
- [Angular 2] Using ng-model for two-way binding
Two-way binding still exists in Angular 2 and ng-model makes it simple. The syntax is a combination ...
- cocos2d-x 背景音乐播放
Code // on "init" you need to initialize your instance bool HelloWorld::init() { bool ...
- jni那点事
今天说一下在jni开发中常另新手迷惑的JNIEnv这个东西 比如一个c语言的函数 JNIEXPORT jstring JNICALL Java_com_mmmmar_nativethread_Main ...
- 4道过滤菜鸟的iOS面试题
网上已经有很多针对各种知识点的面试题,面试时有些人未必真正理解也能通过背题看上去很懂.我自己总结了4道面试题,好快速的判断这个人是否是一个合格的工程师,欢迎大家点评. 1.struct和class的区 ...
- JSON 解析(门店)
package com.j1.mai.action; import java.io.BufferedReader; import java.io.IOException; import java.io ...
- 转载:C#中事件的由来
原文地址 http://www.tracefact.net/CSharp-Programming/Delegates-and-Events-in-CSharp.aspx 感谢博主分享! 我们继续思考转 ...
- Centos7+Apache2.4+php5.6+mysql5.5搭建Lamp环境——为了wordPress
最近想搭建个人博客玩玩,挑来挑去发现口碑不错的博客程序是wordpress,简称wp.虽然是学java路线的程序员,但因入行时间太短,至今没有发现较为称手开源的博客程序,如果各位大神有好的推荐,也希望 ...
- Linux下进程间管道通信小作业
在进行这次作业之前,我们先来看看什么是管道吧! 管道是Linux中很重要的一种通信方式,是把一个程序的输出直接连接到另一个程序的输入,常说的管道多是指无名管道,无名管道只能用于具有亲缘关系的进程之间, ...
- java中的数据库事务处理
/*java使用事务处理,首先要求数据库支持事务,如使用MYSQL的事务功能,就要求mysql的表类型为Innodb,*/ /*InnoDB,是MySQL的数据库引擎之一 与传统的ISAM与MyISA ...
- MemCache缓存和C#自带的Cache缓存
1.MemCache: //初始化 static SockIOPool _pool; // 创建Memcached private static MemcachedClient Create(stri ...