pku acm 1068
来源:互联网 发布:等腰杨辉三角c语言程序 编辑:程序博客网 时间:2024/09/21 08:14
//括号匹配问题#include <iostream>#include <cstdio>using namespace std;int pseq[22];//接收输入p-sequenceint harr[22];//辅助数组,统计pseq[i-1]和pseq[i]之间还有多少个'('没有匹配int wseq[22];//结果w-sequenceint count;int main(){freopen("in.txt","r",stdin);int t; // 1 <= t <= 10cin>>t;while(t--){count = 1;pseq[0] = harr[0] = 0;int n;// 1 <= n <= 20cin>>n;while(n--){cin>>pseq[count];//cout<<pseq[count]<<" ";harr[count] = pseq[count] - pseq[count - 1];count++;}//cout<<endl<<"count = "<<count<<endl;{//beginfor(int i = 1; i < count; i++){if(pseq[i] != pseq[i-1]){wseq[i] = 1;harr[i]--;}else{int j;for(j = i-1; j >= 1; j--){if(harr[j] > 0){harr[j]--;break;}}wseq[i] = i-j+1;}cout<<wseq[i]<<" ";}cout<<endl;}//end}return 1;}
测试数据:
4
1
1
2
2 2
6
4 5 6 6 6 6
9
4 6 6 6 6 8 9 9 9
- pku acm 1068
- pku-acm
- ACM-PKU
- acm pku 1068 Parencodings的实现
- PKU ACM 题目分类
- acm pku 1088 滑雪
- PKU ACM 1579
- PKU ACM 1163
- PKU ACM 1125
- PKU ACM 2081
- Pku acm 2250 Compromise
- PKU ACM 1004
- PKU ACM 1045
- PKU ACM 1046
- PKU ACM 1003
- acm PKU题型分类
- 滑雪-PKU ACM 1088
- ACM PKU 1177 Picture
- 实用SQL语句
- perl 判断数组里面是否含有某个元素
- Java compiler level does not match the version of the installed Java project facet
- ASP.NET缓存数据添加方法一览
- ASP.NET缓存机制基础概念
- pku acm 1068
- 从iOS3到iOS5各版本feature介绍
- 解开Android应用程序组件Activity的"singleTask"之谜
- u-boot-2009.11在MINI2440上的移植 LCD驱动
- C++ Vector 使用心得
- 动态链接库、静态链接库;动态链接、静态链接
- SQLServer中Case的用法
- Windows防火墙操作代码
- DAO工厂类