ACM 杂题 hdu4915 Parenthese sequence
来源:互联网 发布:淘宝下载新版下载安装 编辑:程序博客网 时间:2024/05/19 16:50
ACM 杂题 hdu4915 Parenthese sequence
锻炼问题的一步步分析能力,考察选手细致。
Parenthese sequence
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 0 Accepted Submission(s): 0
Problem Description
bobo found an ancient string. The string contains only three charaters -- "(", ")" and "?". bobo would like to replace each "?" with "(" or ")" so that the string is valid (defined as follows). Check if the way of replacement can be uniquely determined. Note: An empty string is valid. If S is valid, (S) is valid. If U,V are valid, UV is valid.
Input
The input consists of several tests. For each tests: A string s1s2…sn (1≤n≤106).
Output
For each tests: If there is unique valid string, print "Unique". If there are no valid strings at all, print "None". Otherwise, print "Many".
Sample Input
??????(??
Sample Output
UniqueManyNone
Accepted491562MS1320K
/* * Author: NICK WONG * Created Time: 8/5/2014 16:08:26 * File Name: 1005.cpp */#include<iostream>#include<sstream>#include<fstream>#include<vector>#include<list>#include<deque>#include<queue>#include<stack>#include<map>#include<set>#include<bitset>#include<algorithm>#include<cstdio>#include<cstdlib>#include<cstring>#include<cctype>#include<cmath>#include<ctime>#include<iomanip>using namespace std;#define out(x) cout<<#x<<": "<<x<<endlconst double eps(1e-8);const int maxn=1010000;const long long maxint=-1u>>1;const long long maxlong=maxint*maxint;typedef long long lint;char s[maxn];int x,y,z,ll,rr,len;void init(){}int work(){ x=y=z=0; len=strlen(s)-1; if (len%2==1 || s[1]==')' || s[len]=='(') return -1; s[1]='('; s[len]=')'; s[len+1]='('; for (int i=1; i<=len; i++) { if (s[i]=='(') x++; else if (s[i]=='?') {if (x==0 && z==0) x++; else z++;} else if (s[i]==')') { if (x>=1) x--; else z--; if (z<0) return -1; if (x==0 && z==1) { x=1; z=0; } //if (x+z==0 && s[i+1]=='?') s[i+1]='('; } } ll=z-x; if (ll<0) return ll; x=y=z=0; for (int i=len; i>=1; i--) if (s[i]==')') y++; else if (s[i]=='?') z++; else if (s[i]=='(') { if (y>=1) y--; else z--; if (z<0) return -1; } rr=z-y; if (rr<0) return rr; return ll;}int main(){ while(scanf("%s",s+1)!=EOF) { s[0]=')'; init(); int tmp=work(); if (tmp<0) cout<<"None"<<endl; else if (tmp==0) cout<<"Unique"<<endl; else cout<<"Many"<<endl; } return 0;}
0 0
- ACM 杂题 hdu4915 Parenthese sequence
- HDU4915--Parenthese sequence
- HDU4915 Parenthese sequence
- HDU4915 Parenthese sequence
- HDU4915:Parenthese sequence(贪心)
- hdu4915 Parenthese sequence 2014 Multi-University Training Contest 5
- HDU 4915 Parenthese sequence
- hdu 4915 Parenthese sequence
- hdu 4915 Parenthese sequence
- HDU 4915 Parenthese sequence
- HDU-4915-Parenthese sequence
- 【HDOJ 4915】Parenthese sequence
- hdu 4915 Parenthese sequence
- HDOJ 4915 Parenthese sequence
- HDU 4915 Parenthese sequence
- Parenthese sequence -模拟
- hdu 4915 Parenthese sequence(高效)
- 【HDU】4915 Parenthese sequence 贪心
- P2P之UDP穿透NAT的原理与实现(附源代码)
- SharedPreferences用法笔记
- CoreText实现图文混排和点击事件
- VGA时序及其原理
- 复制linux虚拟机时网卡信息不正确的解决办法
- ACM 杂题 hdu4915 Parenthese sequence
- P2P软件的昨天 今天 明天 P2P技术在中国 P2P软件正式进入第三代 P2P将颠覆下一代互联网游戏规则 P2P商业化的思考 C#下用P2P技术实现点对点聊天 P2P流媒体播放:下一代P
- hdu 1152 Brownie Points I
- ElasticSearch集群安装及配置方法
- html常用标签2
- 耿建玲SQL视频总结
- windows下,Python中获取本地磁盘卷标的方法
- Leetcode--Roman to Integer
- 旋转数组的最小数字