博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
poj 3617 Best Cow Line (字符串反转贪心算法)
阅读量:7099 次
发布时间:2019-06-28

本文共 2187 字,大约阅读时间需要 7 分钟。

Best Cow Line
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 9284   Accepted: 2826

Description

FJ is about to take his N (1 ≤ N ≤ 2,000) cows to the annual"Farmer of the Year" competition. In this contest every farmer arranges his cows in a line and herds them past the judges.

The contest organizers adopted a new registration scheme this year: simply register the initial letter of every cow in the order they will appear (i.e., If FJ takes Bessie, Sylvia, and Dora in that order he just registers BSD). After the registration phase ends, every group is judged in increasing lexicographic order according to the string of the initials of the cows' names.

FJ is very busy this year and has to hurry back to his farm, so he wants to be judged as early as possible. He decides to rearrange his cows, who have already lined up, before registering them.

FJ marks a location for a new line of the competing cows. He then proceeds to marshal the cows from the old line to the new one by repeatedly sending either the first or last cow in the (remainder of the) original line to the end of the new line. When he's finished, FJ takes his cows for registration in this new order.

Given the initial order of his cows, determine the least lexicographic string of initials he can make this way.

Input

* Line 1: A single integer: N

* Lines 2..N+1: Line i+1 contains a single initial ('A'..'Z') of the cow in the ith position in the original line

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.

Sample Input

6ACDBCB

Sample Output

ABCBCD

AC代码:
1 #include
2 #include
3 #include
4 #include
5 #include
6 #include
7 #include
8 #include
9 using namespace std;10 char s[2010],s1[2010];11 int compare(int x,int y,int t)12 {13 //cout<
<<"**"<
<
s1[y])23 return 2;24 x++;y++;j++;25 }26 return 0;27 }28 int main()29 {30 int i,j,k,t,m,n;31 while(cin>>t)32 {33 for(int i=0,j=t-1;i
>s[i];36 s1[j]=s[i];37 }38 n=t;39 int x=0,y=0,ans=0;40 while(n--)41 {42 int kk=compare(x,y,n);43 if(kk==1 || kk==0)44 {45 cout<

 

转载地址:http://kfhql.baihongyu.com/

你可能感兴趣的文章
android 循环操作
查看>>
Promise & Deferred objects in JavaScript Pt.1: Theory and Semantics.
查看>>
Joyoi花店橱窗(原tyvj1124)
查看>>
JavaMail基础案例开发
查看>>
被称"硬盘杀手"的几个win7系统服务如何关闭(转)
查看>>
C# 存储过程
查看>>
软件体系结构的第二次实验
查看>>
无聊记记
查看>>
ODI Scenario 场景
查看>>
操作JSON对象
查看>>
iOS 模态视图,视图之间的切换
查看>>
iptables
查看>>
.NET自动识别GB2312与UTF-8编码的文件
查看>>
Linux下apache日志分析与状态查看方法
查看>>
hdu2412(树形dp)
查看>>
js返回函数, 函数名后带多个括号的用法及join()的注意事项
查看>>
【NOIP2007】矩阵取数
查看>>
关于VIM在Win10下的无意义折腾
查看>>
ibatis example Class 使用
查看>>
android的触摸事件(转)
查看>>