hdu5414
来源:互联网 发布:网络奇兵讲的什么 编辑:程序博客网 时间:2024/05/17 07:46
这道题在原先的想法上经过一定的优化就可以过了,但是经过优化后,一直wr,经过一个多小时的抗争,终于明白sbn只要>=tbn就可以了,不一定要严格等于。(sbn,tbn的含义可在代码中找到)
参考来源:http://blog.csdn.net/wangcong9614/article/details/47809239
2015.8.29:
又再推了一遍,其实不难,关键是可能已经做过一遍了吧,希望下次可以装装的说:“这道题呀?虽然我没做过,但是简单,看一眼就成。”容我做会儿白日梦。
原先的代码(超时):
#include<stdio.h>#include<string.h>#include<iostream>using namespace std;#define N 100010#define M 26#define INF 0x3f3f3f3fchar s[N];char t[N];int loca[M];int aloca[M];int main(){ int cas; int win; scanf("%d\n",&cas); while(cas--){ scanf("%s",s); scanf("%s",t); memset(loca,-1,sizeof(loca)); for(int i=0;t[i]!='\0';i++){ int tempch=t[i]-'a'; if(loca[tempch]==-1){ loca[tempch]=i; } } for(int i=0;i<M;i++){ aloca[i]=INF; for(int j=0;j<M;j++){ if(j==i){ continue; } else{ if(loca[j]!=-1&&loca[j]<aloca[i]){ aloca[i]=loca[j]; } } } } //for(int i=0;i<M;i++){ // printf("%d\n",loca[i]); //} if(s[0]!=t[0]){ printf("No\n"); continue; } win=1; int i,j; for(i=1,j=1;t[j]!='\0'&&s[i]!='\0';j++){ if(s[i]==t[j]){ i++; continue; } else{ if(t[j]==s[i-1]){ int temp=t[j]-'a'; if(aloca[temp]>loca[temp]){ win=0; break; } } } } if(win==1){ if(t[j]=='\0'&&s[i]!='\0'){ win=0; } else if(t[j]!='\0'&&s[i]=='\0'){ for(;t[j]=='\0'||t[j]!=s[i-1];j++){ int tempch=s[i-1]-'a'; if(aloca[tempch]>loca[tempch]){ win=0; break; } } } } if(win==0){ printf("No\n"); } else{ printf("Yes\n"); } } return 0;}
过了的代码:
#include<stdio.h>#include<string.h>#include<iostream>using namespace std;#define N 1000100char sa[N];char ta[N];int main(){ int t; scanf("%d",&t); while(t--){ scanf("%s",sa); scanf("%s",ta); int i,j; for(i=0,j=0;sa[i]!='\0'&&ta[j]!='\0';j++){ if(sa[i]==ta[j]){ i++; } } if(sa[i]!='\0'){ printf("No\n"); } else{ char sb=sa[0]; char tb=ta[0]; int sbn=1; int tbn=1; for(int i=1;sa[i]!='\0';i++){ if(sa[i]==sa[i-1]){ sbn++; } else{ break; } } for(int i=1;ta[i]!='\0';i++){ if(ta[i]==ta[i-1]){ tbn++; } else{ break; } } if(sb==tb&&sbn>=tbn){ //printf("%d %d\n",sbn,tbn); printf("Yes\n"); } else{ printf("No\n"); } /*int flag=0; int j; for(j=1;ta[j]!='\0';j++) { if(ta[j]==ta[j-1]) continue; else break; } for(int i=0;i<j;i++) { if(sa[i]!=ta[0]) { flag=1; break; } } if(flag==1){ printf("No\n"); } else{ if(sbn<tbn||sa[0]!=ta[0]){ printf("%d\n",1/0); } printf("Yes\n"); }*/ } } return 0;}
0 0
- hdu5414
- hdu5414
- hdu5414 CRB and String
- hdu5414 CRB and String
- [HDU5414]CRB and String
- 模拟 hdu5414 CRB and String
- hdu5414 CRB and String(构造,模拟)
- HDU5414 CRB and String 字符串+模拟+思维
- 2015 多校联赛 ——HDU5414()
- hdu5414(2015多校10)--CRB and String(字符串匹配)
- nyoj106背包问题【贪心算法】~
- C语言:将16进制字符串转化为int类型值
- AndroX eclipse导入源程序后编译错误 make: *** No rule to make target `all'.C/C++ Problem
- 继续畅通工程(2008浙江大学研究生复试上机题[最小生成树] hdoj 1879 )
- linux USB虚拟串口设备名的修改
- hdu5414
- 深入理解JavaScript系列(16):闭包(Closures)
- (1)整数转换二进制镜像后的值
- (CAPropertyAnimation、CABasicAnimation、CAKeyframeAnimation、CAAnimationGroup介绍)
- C++ int与string的转化
- oracle SQL高级编程
- 【分享】ヨスガノソラ(缘之空) + ハルカナソラ(悠之空) [汉化硬盘版]
- 蓝牙压力测试报抛android.os.TransactionTooLargeException异常分析总结
- 深入理解JavaScript系列(17):面向对象编程之概论