POJ 1068 Parencodings(模拟)
来源:互联网 发布:市场数据分析 编辑:程序博客网 时间:2024/05/22 08:02
http://poj.org/problem?id=1068
题目大意:
给定序列一 求序列二
序列一:从前到后 ')' 前有多少个 '('
序列二:按照序列一的顺序每个 ')' 里有多少个完整的括号(包括本身)
分析:
按照序列一还原括号 模拟查找每个 ')' 在其对应的 '(' 内有多少个 ')' 即可
AC代码:
#include <stdio.h>#include <string.h>char str[100];int temp[100];int main (){ int t; scanf("%d",&t); while (t--){ int n; memset(str,0,sizeof(str)); memset(temp,0,sizeof(temp)); scanf ("%d",&n); for (int i=1;i<=n;i++){ scanf ("%d",&temp[i]); str[temp[i-1]+(temp[i]-temp[i-1])+i-1]=')'; } for (int i=0;i<=(2*temp[n]-temp[n-1]+n-1);i++){ if (str[i]!=')') str[i]='('; } for (int i=0;i<=(2*temp[n]-temp[n-1]+n-1);i++){ if (str[i]==')'){ int temp1=1; int temp2=1; for (int j=i-1;j>=0&&temp1!=0;j--){ if (str[j]==')'){ temp2++; temp1++; } else{ temp1--; } } printf ("%d ",temp2); } } putchar('\n'); } return 0;}
阅读全文
0 0
- poj 1068 Parencodings(模拟)
- poj 1068 Parencodings(模拟)
- poj 1068 Parencodings(模拟)
- poj 1068 Parencodings(模拟)
- POJ 1068 Parencodings (模拟)
- poj 1068 Parencodings(模拟)
- poj 1068 Parencodings(模拟)
- POJ 1068 Parencodings(模拟)
- POJ 1068 Parencodings(模拟)
- POJ 1068:Parencodings(模拟)
- POJ 1068 Parencodings 模拟
- poj 1068 Parencodings (模拟)
- poj 1068 Parencodings 模拟
- POJ 1068-Parencodings(模拟)
- poj 1068 Parencodings(模拟)
- poj 1068 Parencodings 模拟
- POJ - 1068 Parencodings 模拟
- POJ 1068 Parencodings <模拟>
- 用Repo强制同步远程代码
- Linux 用户管理相关文件
- 29
- 30
- 31
- POJ 1068 Parencodings(模拟)
- 32
- 33
- matplotlib bar 柱状图
- 34
- fatal error C1083 分析
- redheat 上python 版本切换后导致yum用不了
- 层次聚类以及k-means算法
- 35