POJ 3617 Best Cow Line [贪心] [字典序最小]
来源:互联网 发布:mac 剪切 编辑:程序博客网 时间:2024/06/09 17:18
POJ 3617 Best Cow Line
给定长度为n 的字符串S,现要构造一个长度为n 的字符串T. 初始T 为空串,随后可以从S 头部删除一个字符加到T 的尾部,或是从S 尾部删除一个字符加到T 的尾部,求字典序最小的T
1 <=n<=2000
那么直接比较两个指针的值是不完全正确的,因为还有相同的情况,为了让字典序最小,需要继续比较指针下一个位置的值,知道两个指针相遇或者有不相同的停止。
#include<iostream>#include<cstdio>#include<cstring>#include<cstdlib>#include<cmath>#include<vector>#include<queue>#include<stack>#include<map>#include<set>#include<string>#include<iomanip>#include<ctime>#include<climits>#include<cctype>#include<algorithm>#ifdef WIN32#define AUTO "%I64d"#else#define AUTO "%lld"#endifusing namespace std;#define smax(x,tmp) x=max((x),(tmp))#define smin(x,tmp) x=min((x),(tmp))#define maxx(x1,x2,x3) max(max(x1,x2),x3)#define minn(x1,x2,x3) min(min(x1,x2),x3)const int INF=0x3f3f3f3f;const int maxn = 2005;char s[maxn],t[maxn];int top;int n;int main(){#ifndef ONLINE_JUDGE freopen("cow.in","r",stdin); freopen("cow.out","w",stdout);#endif scanf("%d",&n); char ch = getchar(); for(int i=0;i<n;i++) { while(!isalpha(ch)) ch=getchar(); s[i]=ch; ch = getchar(); } int head=0,tail=n-1; while(head^tail) { bool isleft=true; for(int i=0;head+i<=tail-i;i++) if(s[head+i]^s[tail-i]) if(s[head+i]<s[tail-i]) { isleft=true;break; } else { isleft=false;break; } if(isleft) t[++top]=s[head++]; else t[++top]=s[tail--]; } t[++top]=s[head]; for(int i=1;i<=top;i++) { putchar(t[i]); if(i%80==0 && i^top) putchar('\n'); } return 0;}
0 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 No.3617-Best Cow Line(字典序最小问题)
- 字典序最小问题-贪心-Best Cow Line-POJ3617
- POJ3617 Best Cow Line(贪心,字典序最小)
- 字典序最小问题Best Cow Line
- poj 3617 Best Cow Line(取字典序最小的一种排序)
- POJ NO.3617 Best Cow Line(字典序最小问题)
- 2.2.3 字典序最小问题 -Best Cow Line(POJ 3617)
- POJ 3617Best 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(贪心)
- 2016.10.4NOIPA组模拟总结
- PopupWindow基本展示,Button底部展示
- PAT乙级1009
- 正则表达式基本语法
- Linux centos (vps) 安装Tomcat7
- POJ 3617 Best Cow Line [贪心] [字典序最小]
- OLTP数据库的归档
- CentOS 6.7 安装zabbix-agent
- CF 721C DAG上的dp
- hdu4433(dp+贪心)
- HDU 5832 A water problem(简单思维题目)【2016中国大学生程序设计竞赛 - 网络选拔赛】
- HTML中使用cookie保存登录账户
- Android Studio 主题插件
- 继续继续