[POJ1068]Parencodings
[POJ1068]Parencodings
试题描述
Let S = s1 s2...s2n be a well-formed string of parentheses. S can be encoded in two different ways:
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.
输入
The first line of the input contains a single integer t (1 <= t <= 10), the number of test cases, followed by the input data for each test case. The first line of each test case is an integer n (1 <= n <= 20), and the second line is the P-sequence of a well-formed string. It contains n positive integers, separated with blanks, representing the P-sequence.
输出
The output file consists of exactly t lines corresponding to test cases. For each test case, the output line should contain n integers describing the W-sequence of the string corresponding to its given P-sequence.
输入示例
输出示例
数据规模及约定
见“输入”
题解
用个栈胡乱搞搞。
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <stack>
#include <vector>
#include <queue>
#include <cstring>
#include <string>
#include <map>
#include <set>
using namespace std; const int BufferSize = 1 << 16;
char buffer[BufferSize], *Head, *Tail;
inline char Getchar() {
if(Head == Tail) {
int l = fread(buffer, 1, BufferSize, stdin);
Tail = (Head = buffer) + l;
}
return *Head++;
}
int read() {
int x = 0, f = 1; char c = Getchar();
while(!isdigit(c)){ if(c == '-') f = -1; c = Getchar(); }
while(isdigit(c)){ x = x * 10 + c - '0'; c = Getchar(); }
return x * f;
} #define maxn 50
int n, S[maxn], top; int main() {
int T = read();
while(T--) {
n = read();
int lst = 0; top = 0;
for(int i = 1; i <= n; i++) {
int x = read();
for(int j = 1; j <= top; j++) S[j] += x - lst;
for(int j = x - lst; j; j--) S[++top] = j;
printf("%d%c", S[top--], i < n ? ' ' : '\n');
lst = x;
}
} return 0;
}
[POJ1068]Parencodings的更多相关文章
- POJ1068——Parencodings
Parencodings Description Let S = s1 s2...s2n be a well-formed string of parentheses. S can be encode ...
- 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_模拟] POJ1068 Parencodings (两种括号编码转化 规律 模拟)
Description Let S = s1 s2...s2n be a well-formed string of parentheses. S can be encoded in two diff ...
- POJ1068 Parencodings(模拟)
题目链接. 分析: 水题. #include <iostream> #include <cstdio> #include <cstring> using names ...
- POJ1068 Parencodings 解题报告
Description Let S = s1 s2...s2n be a well-formed string of parentheses. S can be encoded in two diff ...
- 【数据结构(高效)/暴力】Parencodings
[poj1068] Parencodings Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 26686 Accepted ...
- dir命令只显示文件名
dir /b 就是ls -f的效果 1057 -- FILE MAPPING_web_archive.7z 2007 多校模拟 - Google Search_web_archive.7z 2083 ...
- 备战NOIP每周写题记录(一)···不间断更新
※Recorded By ksq2013 //其实这段时间写的题远远大于这篇博文中的内容,只不过那些数以百记的基础题目实在没必要写在blog上; ※week one 2016.7.18 Monday ...
- 【POJ1068】Parencodings
题目传送门 本题知识点:模拟 这是一道恐怖的括号题.题意稍微理解以下还是可以的. 我们针对样例来理解一下 S.P.W 到底是什么意思: S:( ( ( ( ) ( ) ( ) ) ) ) P: \(P ...
随机推荐
- qt5.4
rm -f libQt5Qml.so.5.4.0 libQt5Qml.so libQt5Qml.so.5 libQt5Qml.so.5.4g++ -Wl,-O1,--sort-common,--as- ...
- vim 使用总结
VIM分屏显示 1 . 水平分屏split(sp) || 垂直分屏vsplit(vs) :(v)split 输入这样的命令后vi就会将当前的窗口平分为两个,并且在这两个窗口中显示的是同一篇文章.如 ...
- win7开防火墙,允许别人远程
- jquery id选择器 id带"."问题
例如控件ID为user.id 使用$("#user.id")不能得到正确的结果 必须使用\\转义 即$("#user\\.id")
- CV界的明星人物们
CV界的明星人物们 来自:http://blog.csdn.net/necrazy/article/details/9380151,另外根据自己关注的地方,加了点东西. 今天在cvchina论坛上看到 ...
- History(历史)命令用法
如果你经常使用 Linux 命令行,那么使用 history(历史)命令可以有效地提升你的效率.本文将通过实例的方式向你介绍 history 命令的用法. 使用 HISTTIMEFORMAT 显示时间 ...
- Web启动服务器上的某一个服务
情景是这样的.. 网页打开一个数据列表..数据要求实时从其他多个平台上获取.. 所以就有了一个Web页面..还有个WinService的服务来定时获取这些数据... 问题来了.. 发现Service有 ...
- Java多线程编程核心技术---线程间通信(一)
线程是操作系统中独立的个体,但这些个体如果不经过特殊处理就不能成为一个整体.线程间的通信就是成为整体的必用方案之一.线程间通信可以使系统之间的交互性更强大,在大大提高CPU利用率的同时还会使程序员对各 ...
- XStream使用总结
最近做webService报文转换的公共接口使用到了XSream工具库,写个小总结备忘... XStream是一个可以将javaBean与XML双向转换的java类库,本文内容基于xstream-1. ...
- 弹出框一 之 基于bootstrap和jquery的自定义弹出框
(function ($) { window.Ewin = function () { var html = '<div id="[Id]" class="moda ...