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 ...
随机推荐
- Luogu P3388 【模板】割点(割顶)
一道求割点的板子题.还是采用经典的Tarjan算法. 首先大致和Tarjan求强连通分量相似,都是用\(dfn_x\)表示访问到\(x\)的时间(时间戳),\(low_x\)表示通过\(x\)回边能走 ...
- [Codeforces1137D]Cooperative Game
[Codeforces1137D]Cooperative Game Tags:题解 题意 这是一道交互题. 给你一张下面这样的地图,由一条长为\(t\)的有向链和一个长为\(c\)的环构成. 现在你有 ...
- vue + element 实现登录注册(自定义表单验证规则)
注册页包含手机验证码登录和密码的二次验证. 效果如下: 实现代码: <template> <div> <div class="register-wrapper& ...
- JMeter:响应结果乱码解决方法
JMeter:响应结果乱码解决方法 我们经常使用jmeter做接口测试或者正则匹配 看到的响应结果存在乱码,这是小白经常会问的问题,这是因为jmeter会按照jmeter.properties文件中, ...
- 有道云笔记导入txt文件的方法
有道云笔记pc版迷之不能导入txt文件 尝试很多方法后发现 通过网页版 有道云 可以直接上传 但是pc版不能查看而移动端可以查看 很迷~
- eclipse添加maven环境
一.打开eclipse,选择Window->preference,如下图所示 二.Maven-> installation->add,见下图: 三.选择Directory,选择mav ...
- 最小生成树模板题POJ - 1287-prim+kruskal
POJ - 1287超级模板题 大概意思就是点的编号从1到N,会给你m条边,可能两个点之间有多条边这种情况,求最小生成树总长度? 这题就不解释了,总结就算,prim是类似dijkstra,从第一个点出 ...
- SE Springer小组之《Spring音乐播放器》可行性研究报告一、二(转载)
此文转载自组员小明处~~ 1 引言 1.1编写目的 <软件工程>课程,我们团队计划开发一个音乐播放器.本文档是基于网络上现有的音乐播放器的特点,团队计划实现的音乐播放器功能和团队 ...
- Mock.js的简易使用
一:安装 npm install mockjs --save-dev 二:引入 在src目录下创建mock.js文件,输入以下代码: // 引入mockjs const Mock = require( ...
- JavaScript 模拟 HashMap例子
function map(){ var map = {}; // Map map = new HashMap(); var key = "key"; va ...