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 ...
随机推荐
- android 时间对话框 TimePickerDialog简介
个人也提醒功能的时候用到了TimePickerDialog对话框,查阅了非常多技术资料,可是感觉非常多东西都说的不是非常具体,而且非常多地方.都有不完好的地方.比方有弹出对话框得到的不是系统当前 ...
- [转] linux中cat more less head tail 命令
1.cat 显示文件连接文件内容的工具: cat 是一个文本文件查看和连接工具.查看一个文件的内容,用cat比较简单,就是cat 后面直接接文件名. 比如: [root@localhost ~]# c ...
- Android图片异步加载之Android-Universal-Image-Loader(转)
今天要介绍的是Github上一个使用非常广泛的图片异步加载库Android-Universal-Image-Loader,该项目的功能十分强大,可以说是我见过的目前功能最全.性能最优的图片异步加载解决 ...
- Centos ssh 登陆乱码解决办法
1.vi /etc/sysconfig/i18n 将内容改为 LANG="zh_CN.GB18030"LANGUAGE="zh_CN.GB18030:zh_CN.GB23 ...
- C#HttpWebResponse请求常见的状态码
成员名称 说明 Continue 等效于 HTTP 状态 100.Continue 指示客户端可能继续其请求. SwitchingProtocols 等效于 HTTP 状态 101.Switching ...
- javascript的继承种类
继承一般要实现以下三层含义: 1)子类实例可以共享父类的方法: 2)子类可以覆盖父类的方法或者扩展新的方法: 3)子类和父类都是子类实例的类型. 一.构造继承法 子类中调用父类的构造函数来维护的,该继 ...
- JS 改变input 输入框样式
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <hea ...
- KMP算法总结
kmp算法的T子字符串的下标的变化规律 大话数据结构这边书中的KMP算法的讲解跟最终的算法代码还是有很大的差别 java语言只会if判断语句,循环语句,但是这些语句以及可以包罗万象了,可以适用很多情况 ...
- Swift - 25 - 控制转移和二维数组
//: Playground - noun: a place where people can play import UIKit // fallthrough // fallthrough会在当前c ...
- web初识-tomcat的基本使用
Web入门 1. 软件结构: C/S : 有客户端, 维护较麻烦, 需要客户端和服务器端都更新. B/S : 优点 : 客户端就是浏览器, 更新方便, 只需要更新服务器端即可 ...