poj1068 【模拟】
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<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<set>
#include<list>
using namespace std;
#define ll long long
const int Mod = 1e9+;
const int inf = 1e9;
const int Max = 1e5+;
vector<int>vt[Max];
//void exgcd(ll a,ll b,ll& d,ll& x,ll& y){if(!b){d=a;x=1;y=0;}else{exgcd(b,a%b,d,y,x);y-=x*(a/b);}}
//ll inv(ll a,ll n){ll d, x, y;exgcd(a,n,d,x,y);return (x+n)%n;} ��Ԫ
//int gcd(int a,int b) { return (b>0)?gcd(b,a%b):a; } ��С��Լ
//int lcm(int a, int b) { return a*b/gcd(a, b); } ������
int main()
{
int n,m,i,j,a[],c[],vis[],ans;
char b[];
cin>>n;
while(n--){
cin>>m;
memset(vis,,sizeof(vis));
for(i=;i<m;i++)
cin>>a[i];
for(i=;i<*m;i++)
b[i] = '(';
for(i=;i<m;i++)
b[a[i]+i] = ')';
for(i=;i<m;i++){
ans = ;
for(j=a[i]+i-;j>=;j--){
if(b[j]=='('&&vis[j]==)
ans++;
else if(b[j]=='('&&vis[j]==){
vis[j]=;
ans++;
c[i] = ans;
break;
}
}
}
for(i=;i<m-;i++)
cout<<c[i]<<" ";
cout<<c[m-]<<endl;
}
return ;
}
poj1068 【模拟】的更多相关文章
- poj1068 模拟
Parencodings Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 25010 Accepted: 14745 De ...
- [ACM_模拟] POJ1068 Parencodings (两种括号编码转化 规律 模拟)
Description Let S = s1 s2...s2n be a well-formed string of parentheses. S can be encoded in two diff ...
- poj1068解题报告(模拟类)
POJ 1068,题目链接http://poj.org/problem?id=1068 题意: 对于给出给出的原括号串S,对应两种数字密码串P.W: S (((()()()))) P- ...
- [poj1068]Parencodings_模拟
Parencodings 题目大意:给你一个P序列,表示从左到右的右括号左边有多少左括号,求M序列. 注释:M序列定义为每一个右括号左边最近的没有被之前的右括号匹配的括号之间,有多少已经匹配的括号队对 ...
- POJ1068 Parencodings(模拟)
题目链接. 分析: 水题. #include <iostream> #include <cstdio> #include <cstring> using names ...
- POJ1068 --(模拟)
这题是在看一个书的时候的一个例题,当时并不明白啥意思,于是便找了下原题,以前没在POJ上刷过,这是开了个头,以后努力刷这个网站 题目大概意思是:http://poj.org/problem?id=10 ...
- POJ-1068 Parencodings---模拟括号的配对
题目链接: https://vjudge.net/problem/POJ-1068 题目大意: 给出一种括号序列的表示形式名叫P序列,规则是统计出每个右括号之前的左括号个数作为序列每项的值.然后要求你 ...
- App开发:模拟服务器数据接口 - MockApi
为了方便app开发过程中,不受服务器接口的限制,便于客户端功能的快速测试,可以在客户端实现一个模拟服务器数据接口的MockApi模块.本篇文章就尝试为使用gradle的android项目设计实现Moc ...
- 故障重现, JAVA进程内存不够时突然挂掉模拟
背景,服务器上的一个JAVA服务进程突然挂掉,查看产生了崩溃日志,如下: # Set larger code cache with -XX:ReservedCodeCacheSize= # This ...
随机推荐
- 3.5《想成为黑客,不知道这些命令行可不行》(Learn Enough Command Line to Be Dangerous)—第三章小结
本章使用的重要命令总结在Table 5中 命令 描述 示例 curl 与URL交互 $ curl -O example.com which 指出程序的在计算机的路径 $ echo bar >&g ...
- 学习angularjs的ng-hide和ng-disabled
一,页面上有一个checkbox和一个文本框.切换checkbox能对文本框输入文本与否: <input type="checkbox" ng-model="ckS ...
- 2019 The 19th Zhejiang University Programming Contest
感想: 今天三个人的状态比昨天计院校赛的状态要好很多,然而三个人都慢热体质导致签到题wa了很多发.最后虽然跟大家题数一样(6题),然而输在罚时. 只能说,水题还是刷得少,看到签到都没灵感实在不应该. ...
- [清华集训2017]榕树之心[树dp]
题意 题目链接 分析 首先解决 \(subtask3\) ,我们的策略就是进入子树,然后用其它子树来抵消,注意在子树内还可以抵消. 可以转化为此模型:有一个数列 \(a\) ,每次我们可以选定两个值 ...
- .NetCore实践篇:分布式监控Zipkin持久化之殇
前言 本系列已写了四篇文章,读本篇之前,可以先读前面几篇. 思考大纲:.Net架构篇:思考如何设计一款实用的分布式监控系统? 实践篇一:.NetCore实践篇:分布式监控客户端ZipkinTracer ...
- WPF没落了吗?
从08年开始一直到现在,碰到所有的项目,我个人经手的,都用wpf开发. wpf应该说一直没有火过,一直平平淡淡. 个人为什么一直执着用wpf,开始使用是因公司项目,做了两年wpf开发,后来换工作一直搜 ...
- Telephone Phrases
There are some common phrases and sentences you can use when speaking on the telephone. The informal ...
- php5.6安装Zend Opcache扩展
假设php5.6安装路径为/data2/php[root@nextcloud src]# pwd/usr/local/src[root@nextcloud src]# wget http://pecl ...
- 点评qq浏览器
1.内核. qq浏览器用的是是IE8的内核,而且是只有IE内核,所以,在速度上没办法跟那些webkit内核做对比了,不过也没有太慢,在沈航的网速下,打开网页的速度也还是勉强可以接受的. ...
- beta阶段性能指标测试
性能指标概况 安装耗时 启动耗时 CPU占用 内存占用 电池温度 网络流量 平均值 5.48s 1.04s 1.61% 18.68MB 32.44℃ 93.78B 峰值 131.74s 5.13s 5 ...