poj 1068(模拟题)
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 23545 | Accepted: 13802 |
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 思路:简单回溯即可;
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<iomanip>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
using namespace std;
#define PI 3.141592653589792128462643383279502
int main(){
freopen("in.txt","r",stdin);
int t,n,m,c,p[],pp[];
bool w[];
cin>>t;
while(t--){
memset(w,true,sizeof(w));
cin>>n;
c=;
for(int i=;i<=n;i++){
cin>>m;
w[m+i]=false;
p[c++]=m+i;
}
int k=,b=,kk;
for(int i=;i<c;i++){
kk=p[i];
for(int j=kk;j>=;j--){
if(w[j]==false)
k++;
else
b++;
if(b-k==) {
pp[i]=k;
k=;b=;
break;
}
}
}
for(int i=;i<c;i++){
if(i!=)cout<<" ";
cout<<pp[i];
}
cout <<endl;
}
return ;
}
poj 1068(模拟题)的更多相关文章
- poj 1068 模拟
题目链接 大概题意就是告诉你有个n个小括号,每一个")"左边有多少个"("都告诉你了,然后让你求出每一对括号之间有多少对括号(包含自己本身). 思路: 我先计算 ...
- 模拟 POJ 1068 Parencodings
题目地址:http://poj.org/problem?id=1068 /* 题意:给出每个右括号前的左括号总数(P序列),输出每对括号里的(包括自身)右括号总数(W序列) 模拟题:无算法,s数组把左 ...
- poj 1008:Maya Calendar(模拟题,玛雅日历转换)
Maya Calendar Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 64795 Accepted: 19978 D ...
- POJ 3393 Lucky and Good Months by Gregorian Calendar 模拟题
题目:http://poj.org/problem?id=3393 不多说了,简单模拟题,因为粗心写错了两个字母,导致错了N遍,模拟还是一贯的恶心,代码实在不想优化了,写的难看了点.. #includ ...
- POJ 3923 Ugly Windows(——考察思维缜密性的模拟题)
题目链接: http://poj.org/problem?id=3923 题意描述: 输入一个n*m的屏幕 该屏幕内有至少一个对话框(每个对话框都有对应的字母表示) 判断并输出该屏幕内处于最表层的对话 ...
- poj 1888 Crossword Answers 模拟题
Crossword Answers Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 869 Accepted: 405 D ...
- POJ 模拟题集合
http://www.cppblog.com/Uriel/articles/101592.html 感觉这个暑假没有去年有激情啊,,,还没到状态就已经块上学了,,, 真是弱暴了,,,找几道模拟题刷刷. ...
- POJ 1008 简单模拟题
e.... 虽然这是一道灰常简单的模拟题.但是米做的时候没有读懂第二个日历的计时方法.然后捏.敲完之后华丽的WA了进一个点.坑点就在一年的最后一天你是该输出本年的.e ...但是我好想并没有..看di ...
- POJ - 1835 宇航员(模拟题)
问题描述: 宇航员在太空中迷失了方向,在他的起始位置现在建立一个虚拟xyz坐标系,称为绝对坐标系,宇航员正面的方向为x轴正方向,头顶方向为z轴正方向,则宇航员的初始状态如下图所示: 现对六个方向分别标 ...
- POJ推荐50题
此文来自北京邮电大学ACM-ICPC集训队 此50题在本博客均有代码,可以在左侧的搜索框中搜索题号查看代码. 以下是原文: POJ推荐50题1.标记“难”和“稍难”的题目可以看看,思考一下,不做要求, ...
随机推荐
- os.fork()
ret = os.fork() if ret == 0: child_suite # 子进程代码 else: parent_suite # 父进程代码 Python中的fork() 函数可以获得系统中 ...
- 【BZOJ2850】巧克力王国 [KD-tree]
巧克力王国 Time Limit: 60 Sec Memory Limit: 512 MB[Submit][Status][Discuss] Description 巧克力王国里的巧克力都是由牛奶和 ...
- hdu5909 Tree Cutting
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=5909 [题解] 设$f_{x,i}$表示以$x$节点的子树中,权值为$i$的子树个数,其中$x$必选. ...
- Remmarguts' Date(POJ2449+最短路+A*算法)
题目链接:http://poj.org/problem?id=2449 题目: 题意:求有向图两点间的k短路. 思路:最短路+A*算法 代码实现如下: #include <set> #in ...
- 爬虫--requests讲解
什么是requests? Requests是用Python语言编写,基于urllib,采用Apache2 Licensed 开源协议的HTTP库.它比urllib更加方便,可以节约我们大量的工作,完全 ...
- linux内存占用查看
查看内存使用情况 free free -m //显示单位为:兆 查看占用内存最高的5个进程ps aux | sort -k4nr | head -n 5 查看占用CPU最高的5个进程ps aux | ...
- 通过JDBC连接HiveServer2
如果通过JDBC连接HiveServer2时提示:User: hive is not allowed to impersonate hive,需要在core-site.xml中新增如下配置: hado ...
- Perl6 Bailador框架(7):模版编写
先看一个例子: use v6; use Bailador; my $data = ' <form action="", method="get"> ...
- 【R语言学习】时间序列
时序分析会用到的函数 函数 程序包 用途 ts() stats 生成时序对象 plot() graphics 画出时间序列的折线图 start() stats 返回时间序列的开始时间 end() st ...
- 110.Balanced Binary Tree---《剑指offer》面试39
题目链接 题目大意:判断一个二叉树是否是平衡二叉树. 法一:dfs.利用求解二叉树的高度延伸,先计算左子树的高度,再计算右子树的高度,然后两者进行比较.o(nlgn).代码如下(耗时4ms): pub ...