POJ3623 Best Cow Line,Gold
来源:互联网 发布:js字符串加逗号 编辑:程序博客网 时间:2024/06/02 21:42
题意:给一个字符串,每次从开头和结尾中取一个字符,求取完后按顺序取的字符所组成的字符串中字典序最小的字符串。
直接暴力,从开头和结尾中取一个字典序最小的字符,如果两个字符字典序相等,就while循环查找它们靠近中间的两个字符字典序最小的。如果没找到(回文串),就随便取。
#include<stdio.h>#include<string.h>#include<algorithm>#include<map>#include<vector>using namespace std;const int maxn = 30002, inf = 1000000002;int n;char ch[maxn][3];char ans[maxn];int main(){ //freopen("1.txt", "r", stdin); //freopen("2.txt","w",stdout); scanf("%d", &n); for(int i=1;i<=n;i++) { scanf("%s",ch[i]); } int i=1,j=n ,cnt=0; while(i<j) { if(ch[i][0]<ch[j][0]) ans[cnt++]=ch[i][0],i++; else if(ch[i][0]>ch[j][0]) ans[cnt++]=ch[j][0],j--; else if(ch[i][0]==ch[j][0]) { int ti=i,tj=j; while(ti<tj) { if(ch[ti][0]<ch[tj][0]) { ans[cnt++]=ch[i][0],i++; break; } if(ch[ti][0]>ch[tj][0]) { ans[cnt++]=ch[j][0],j--; break; } ti++,tj--; } if(ti>=tj) ans[cnt++]=ch[i][0],i++; } if(i==j) ans[cnt++]=ch[i][0],i++; } for(int k=0;k<strlen(ans);k++) { if(k%80==0&&k!=0) printf("\n"); printf("%c",ans[k]); } return 0;}
0 0
- POJ3623 Best Cow Line,Gold
- POJ3623-Best Cow Line, Gold
- poj3623 Best Cow Line, Gold(贪心)
- POJ3623:Best Cow Line, Gold(后缀数组)
- POJ3623 Best Cow Line, Gold 【后缀数组】
- Cpp环境【POJ3623】【Usaco2007Dec】【Vijos2993】Best Cow Line, Gold 最佳队列[2]
- PKU 3623 Best Cow Line, Gold
- POJ-3623-Best Cow Line, Gold
- poj 3623 Best Cow Line, Gold
- POJ 3623 Best Cow Line, Gold(模拟)
- POJ 3623 Best Cow Line, Gold(模拟)
- poj 3623 Best Cow Line, Gold(贪心)
- POJ 3623Best Cow Line, Gold
- 贪心 洛谷P2870 Best Cow Line, Gold
- poj 3623 Best Cow Line, Gold 暴力枚举
- POJ 3623 Best Cow Line, Gold(贪心)
- [贪心+后缀数组] poj 3623 Best Cow Line, Gold
- POJ 3623 Best Cow Line, Gold(贪心)
- Unity3d的Build后处理,和场景build前处理
- HUNNU11306 Parencedence!
- ASCII码表
- 小菜一碟 - WHCTF - 2016 - Reverse
- Big Number
- POJ3623 Best Cow Line,Gold
- 校招季--献给前端求职路上的你们(JS)
- java设计模式_抽象工厂模式
- nyoj 448 寻找最大数
- activity的进入与退出动画
- 设计模式 (7)类图四
- 工作中的小问题之日历显示篇
- Flash中的attachMovie用法之“深度”属性
- LeetCode-136:Single Number