POJ1068 Parencodings(模拟)
来源:互联网 发布:用波士顿矩阵分析海尔 编辑:程序博客网 时间:2024/05/29 13:54
Parencodings
题目链接:
http://poj.org/problem?id=1068
解题思路:
规则就是:每个右括号之前的左括号数序列为P=4 5 6 6 6 6,而每个右括号所在的括号内包含的括号数为W=1 1 1 4 5 6。简单模拟即可。
wrong了很多次,如果你用数组保存,就把数组开到100以上,最好不用。
AC代码(没用数组保存):
#include <iostream>#include <cstdio>using namespace std;int main(){ int T; scanf("%d",&T); while(T--){ int n,ch[100],x,t1 = 0,t2; int i,j,ans = 0; scanf("%d",&n); for(i = 0; i < n; i++){ scanf("%d",&x); t2 = x-t1; for(j = 0; j < t2; j++) ch[ans++] = 0; ch[ans++] = 1; t1 = x; } //cout<<ans<<endl; for(i = 0; i < ans; i++) //cout<<ch[i]<<endl; for(i = 0; i < ans; i++) if(ch[i] == 1){ int sum = 1,t = 1; for(j = i-1;; j--){ if(ch[j] == 0) t--; if(ch[j] == 1){ t++; sum++; } if(t == 0){ printf("%d ",sum); break; } //cout<<sum<<endl; } } printf("\n"); } return 0;}
AC代码(用数组保存):
#include <iostream>#include <cstdio>using namespace std;int main(){ int T; scanf("%d",&T); while(T--){ int n,p[100],w[100],ch[10000]; int i,j,ans = 0; scanf("%d",&n); for(i = 0; i < n; i++) scanf("%d",&p[i]); for(i = 0; i < p[0]; i++) ch[ans++] = 0; ch[ans++] = 1; for(i = 1; i < n; i++){ int t = p[i]-p[i-1]; for(j = 0; j < t; j++) ch[ans++] = 0; ch[ans++] = 1; } //cout<<ans<<endl; for(i = 0; i < ans; i++) if(ch[i] == 1){ int sum=1,t=1; for(j = i-1;; j--){ if(ch[j] == 0) t--; if(ch[j] == 1){ t++; sum++; } if(t == 0){ printf("%d ",sum); break; } //cout<<sum<<endl; } } printf("\n"); } return 0;}
0 0
- POJ1068 Parencodings(模拟)
- POJ1068 Parencodings (模拟)
- Parencodings(poj1068简单模拟)
- POJ1068 Parencodings(模拟,括号问题)
- POJ1068《Parencodings》方法:模拟
- POJ1068 Parencodings(模拟)
- POJ1068 Parencodings 模拟题
- POJ1068 Parencodings(模拟)
- poj1068 Parencodings 【模拟】
- poj1068 Parencodings 模拟 栈
- Parencodings(POJ1068 模拟)
- poj1068 Parencodings 模拟水题
- poj1068 Parencodings【模拟】【刷题计划】
- Parencodings poj1068
- POJ1068 Parencodings
- poj1068--Parencodings
- POJ1068-Parencodings
- POJ1068 Parencodings
- 中国用人做事模式
- SQL exists 与 in
- JDBC 与JAVA 数据库编程
- idle in transaction
- HBASE之RowKey排序解析
- POJ1068 Parencodings(模拟)
- tomcat启动端口错误
- 如何强制用户通过HTTPS访问网站
- UTF8文件读写
- BI publisher在word 2007消失的解决办法
- JAVA的getBytes()
- Xcode环境下osip,eXosip, openssl的静态库编译方法(编译出来给IOS使用)
- C/C++基本知识(二)
- APP适配IOS8,iPhone6和Plus截图简要说明,有iP6截图下载供研究(原创)