POJ-3617-Best Cow Line
2013-06-29 19:31
656 查看
这个题就是说给你一系列字母, 要你取出字典序最小的字符串,每次只能从最上面或者最下面进行取
贪心做即可~每次从上和从下选择最小的,若相等则向中间搜索
代码:
贪心做即可~每次从上和从下选择最小的,若相等则向中间搜索
代码:
#include<cstdio> #include<cstring> #include<iostream> using namespace std; int n,str[2011]; int main() { while(scanf("%d",&n)!=EOF) { char ch; for(int i=0;i<n;i++) { getchar(); ch=getchar(); str[i]=ch-'A'; } int pre=0,last=n-1,count=0; for(int i=0;i<n;i++) { if(str[pre]==str[last]) { int pr=pre,la=last,flag=0; while(pr<=la) { if(str[pr]<str[la]) { printf("%c",str[pre]+'A'); count++; flag=1; pre++; break; } else if(str[pr]>str[la]) { printf("%c",str[last]+'A'); count++; flag=1; last--; break; } pr++,la--; } if(!flag) { printf("%c",str[pre]+'A'); count++; pre++; } } else if(str[pre]<str[last]) { printf("%c",str[pre]+'A'); count++; pre++; } else { printf("%c",str[last]+'A'); count++; last--; } if(count==80) { count=0; printf("\n"); } } if(count) printf("\n"); } return 0; }
相关文章推荐
- POJ 3617 Best Cow Line
- POJ 3617 Best Cow Line 贪心算法
- POJ 3617 Best Cow Line
- POJ 3617 Best Cow Line(模拟+贪心)
- POJ 3617 Best Cow Line [贪心] [字典序最小]
- POJ 3617 Best Cow Line
- 【贪心】POJ 3617 Best Cow Line
- POJ_3617_Best Cow Line
- 刷题——Best Cow Line POJ - 3617
- poj 3617 Best Cow Line
- POJ 3617 Best Cow Line(水)
- POJ 3617 Best Cow Line
- POJ 3617 Best Cow Line (贪心)
- POJ3617——Best Cow Line
- POJ 3617 Best Cow Line ||POJ 3069 Saruman's Army贪心
- POJ 3617 Best Cow Line(贪心)
- Best Cow Line POJ - 3617
- POJ 3617 Best Cow Line 贪心
- poj 3617 Best Cow Line 解题报告
- 挑战2.2 Best Cow Line(POJ 3617)