LightOJ 1051 Good or Bad
来源:互联网 发布:淘宝视频下载地址提取 编辑:程序博客网 时间:2024/06/06 00:42
题意:给你一个字符串,只包含大写字母和‘?’,如果字符串中出现了连续三个以上的元音字母或者连续五个以上的辅音字母,则这个字符串是bad,不然就是good.
‘?’号可以替换任意字母,即可bad有可good,则输出Mixed.
分析:dpy[i][j]表示到i为止,连续j个元音可否达到。dpf表示辅音。
这个转移当达到3个元音或者5个辅音时后面就不在转移了,即全是零。 所以找是否是mixed只需扫最后一个位置的前两个元音或者前4个辅音是否不为0。
不懂可以打印下屏蔽的代码,研究下。
#include<iostream>#include<algorithm>#include<cstdio>#include<cmath>#include<cstring>#include<string>#include<vector>#include<cctype>#include<set>#include<map>#include<queue>#include<stack>#include<iomanip>#include<sstream>#include<limits>#define ll long long#define inf 0x3f3f3f3fusing namespace std;const int N= 2000;const int maxn = 1e2+10;const int maxm = 2000000001;const int MOD = 1000;int dpy[maxn][maxn],dpf[maxn][maxn]; //元音 辅音 到i为止,连续j个元音可否达到char str[maxn];int main(){#ifdef LOCALfreopen("C:\\Users\\lanjiaming\\Desktop\\acm\\in.txt","r",stdin);//freopen("output.txt","w",stdout);#endifios_base::sync_with_stdio(0); int T,kase = 0; cin>>T; while(T--) { cout<<"Case "<<++kase<<": "; cin>>str; int len = strlen(str); memset(dpy,0,sizeof(dpy)); memset(dpf,0,sizeof(dpf)); for(int i = 0; i < len; i++) { int x; if (str[i] == '?') x = 0; else if (str[i] == 'A' || str[i]=='E' || str[i]=='I' || str[i]=='O'||str[i]=='U') x = 1; else x = 2; if (i==0) { if ( x == 1 || x == 0) dpy[0][1] = 1; if ( x == 2 || x == 0) dpf[0][1] = 1; }else { for(int j = 0; j <= 2; j++) if (dpy[i-1][j]) { if ( x == 1 || x == 0) dpy[i][j+1] = 1; if ( x == 2 || x == 0) dpf[i][1] = 1; } for(int j = 0; j <= 4; j++) if (dpf[i-1][j]) { if ( x == 1 || x == 0) dpy[i][1] = 1; if ( x == 2 || x == 0) dpf[i][j+1] = 1; } } } /* for(int i = 0; i < len; i++) { cout<<i<<endl; for(int j = 0; j <= 3; j++) cout<<dpy[i][j]<<" ";cout<<endl; for(int j = 0; j <= 5; j++) cout<<dpf[i][j]<<" ";cout<<endl; }*/ bool ok1 =false,ok2 = false; for(int i = 0; i < len; i++) if (dpy[i][3] || dpf[i][5]) ok2 =true; for(int i = 0; i <= 2; i++) if (dpy[len-1][i]) ok1 =true; for(int i = 0; i <= 4; i++) if (dpf[len-1][i]) ok1 =true; if (ok1 && ok2 ) cout<<"MIXED\n"; else if (ok1) cout<<"GOOD\n"; else cout<<"BAD\n"; }return 0;}
0 0
- LightOJ 1051 Good or Bad
- LightOJ 1051 Good or Bad
- LightOJ 1051 Good or Bad 解题报告
- LightOJ - 1051 Good or Bad(扫描)
- LightOJ 1051 - Good or Bad(dp)
- LightOJ 1051 - Good or Bad (dp)
- LightOJ 1051 - Good or Bad(DP)
- lightoj 1051 - Good or Bad DP
- LightOJ 1051 Good or Bad (递推DP)
- good man or bad man?
- STORED PROCEDURES: GOOD OR BAD(存储过程:好还是坏)
- Are You a Good Leader or a Bad Leader
- good and bad
- Good Bad Books
- good day !bad day !
- Good vs Bad Leader
- Good and Bad PHP Code
- c++ good() eof() fail() bad()
- 使用Node.js+Socket.IO搭建WebSocket实时应用
- Android 自定义进度条
- 线程的生命周期
- HTML5 WebSocket
- Java-Character类中的实用方法
- LightOJ 1051 Good or Bad
- HDU3746Cyclic Nacklace
- 一种基于透明计算的智能终端软件更新方法
- Android 之高仿活动时分秒倒计时
- HDU 1232 畅通工程 (并查集)
- [开源学习_MeiZhi]首次进入App执行某操作,第二次进入则不再执行
- #508 Wiggle Sort
- vijos1037 搭建双塔(重庆一中高2018级信息学竞赛测验7) 解题报告
- Struts2中iterator标签遍历map总结