3069 Best Cow Line(贪心算法)
来源:互联网 发布:网页在线人数统计php 编辑:程序博客网 时间:2024/06/06 06:34
牛的编号
贪心算法,按照字典序比较S和反转后的S2;如果s小则从s头取出一个文字输入到 t中;如果s2小,则从s2中取,相等无所谓
注意的是输出格式问题
Output
The least lexicographic string he can make. Every line (except perhaps the last one) contains the initials of 80 cows ('A'..'Z') in the new line.
#include <iostream>#include<cstdio>using namespace std;int n;char s[2005];char t[2005];void solve(){ int num=0; int a=0,b=n-1; while(a<=b) { bool left=false; for(int i=0;i+a<=b;i++) { if(s[i+a]<s[b-i]) { left=true; break; } else if(s[i+a]>s[b-i]) { left=false; break; } } num++; if(left) putchar(s[a++]); else putchar(s[b--]); if((num)%80==0)//控制输出格式 printf("\n"); } cout<<endl;}int main(){ cin>>n; for(int i=0;i<n;i++) cin>>s[i]; solve(); return 0;}
0 0
- 3069 Best Cow Line(贪心算法)
- Best Cow Line ---- 贪心算法
- Best Cow Line (贪心)
- POJ 3617 Best Cow Line 贪心算法
- POJ 3617 Best Cow Line 贪心算法
- POJ - Best Cow Line(贪心)
- POJ 3617 - Best Cow Line(贪心)
- poj 3617 Best Cow Line(贪心)
- poj3623 Best Cow Line, Gold(贪心)
- 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(贪心)
- poj3617 Best Cow Line (贪心)
- poj3617 Best Cow Line(贪心+字符串)
- poj 3617 Best Cow Line(贪心)
- poj3617 Best Cow Line 贪心
- Could not download artifact 'com.android.tools.build:gradle:0.13.0:gradle.jar'插件无法下载问题
- sql分组按条件统计count case when then
- python3.x爬虫学习:股票数据定向爬虫笔记
- poj 1002 487-3279
- vuejs中执行npm run dev出现页面cannot GET/问题
- 3069 Best Cow Line(贪心算法)
- java
- Maven-在Eclipse中检出并导入Maven项目
- CSS3 选择器——属性选择器
- 缓冲输出字符流_BufferedWriter类
- 第24题:Swap Nodes in Pairs
- linux下WMB通过ODBC连接数据库
- openresty 静态编译
- 为什么需要进程间通信??