贪心,模拟,构造(HDU 5414,CRB and String)
来源:互联网 发布:广州数据恢复 价格 编辑:程序博客网 时间:2024/05/14 03:38
WA了好久。。
No写成了NO
Yes写成了YES
读题:没问题
算法:光是正确构造出来一个结果是远远不够的,我们更应该考虑在构造的过程中所使用的算法(比如贪心)是否会使得后面的构造失败。
实现:没问题
细节:No写成了NO,Yes写成了YES
代码
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;const int maxl = 100010;char s[maxl],t[maxl];int sl,tl;int sk,tk;int solve(){ scanf("%s %s",s,t); if(s[0]!=t[0]) return 0*puts("No"); sl=strlen(s); tl=strlen(t); int sb=1; while(sb<min(sl,tl)&&s[sb]==t[sb]&&t[sb]==t[sb-1]) sb++; tk=tl-1; for(sk=sl-1;sk>=sb;sk--) { while(tk>=sb&&t[tk]!=s[sk]) tk--; if(tk<sb) return 0*puts("No"); tk--; } if(tk>=sb&&t[sb]==t[sb-1]) return 0*puts("No"); return 0*puts("Yes");}int main(){ int T; scanf("%d",&T); while(T--) solve(); return 0;}
阅读全文
0 0
- 贪心,模拟,构造(HDU 5414,CRB and String)
- hdu 5414 CRB and String(贪心)
- HDU 5414 CRB and String(贪心)
- hdu 5414 CRB and String(贪心)
- hdu5414 CRB and String(构造,模拟)
- hdu 5414 CRB and String (贪心)
- hdu 5414 CRB and String(字符串模拟)
- hdu 5414 CRB and String(字符串模拟)
- [HDU 5414] CRB and String (构造+脑洞)
- HDU 5414 CRB and String(水~)
- HDU 5414 CRB and String
- hdu 5414 CRB and String
- HDU 5414 CRB and string
- hdu 5414 CRB and String
- HDU 5414CRB and String
- HDOJ 5414 CRB and String 模拟
- hdu 5414 CRB and String(想法题)
- [思路题] hdu 5414 CRB and String
- Liunx中find命令详解
- Unity3D UniRx ReactiveX响应式编程初探1 双击的检测
- PyQuery库使用
- H5页面调用客户端登陆说明----转(收藏)
- 用 Scrapy 抓取某家的楼盘信息
- 贪心,模拟,构造(HDU 5414,CRB and String)
- c xml 格式化对齐
- 第六周错题回顾
- 剑指offer--面试题25:合并两个排序的链表
- POJ-1149 PIGS(最大流)
- 进程和线程的简单解释
- java多线程之间通信
- 用tarjan求割点
- 条件编译与extern "C"