poj 3623 Best Cow Line, Gold (题意和3617一样只要代码中的范围改一下)
来源:互联网 发布:云免软件下载 编辑:程序博客网 时间:2024/05/16 17:07
Description
FJ is about to take his N (1 ≤ N ≤ 30,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
ABCBCDAC代码:
#include <stdio.h>//author:YangSirchar a[30005];int main(){int n,i,num,flag,l,r;scanf("%d",&n);for(i=0;i<n;i++)scanf("%*c%c",&a[i]);l=0;r=n-1;num=0;while(l<=r){flag=0;for(i=0;i<=r-l;i++){if(a[i+l]<a[r-i]){flag=0;break;}else if(a[i+l]>a[r-i]){flag=1;break;}}if(flag)printf("%c",a[r--]);elseprintf("%c",a[l++]);num++;if(num%80==0)printf("\n");}if(num%80)printf("\n");return 0;}
#include <stdio.h>//author:YangSirchar a[30005];int main(){int n,i,num,flag,l,r,ll,rr;scanf("%d",&n);for(i=0;i<n;i++)scanf("%*c%c",&a[i]);l=0;r=n-1;num=0;while(l<=r){if(a[l]<a[r])printf("%c",a[l++]);else if(a[l]>a[r])printf("%c",a[r--]);else{ll=l;rr=r;while(a[ll]==a[rr]){ll++;rr--;}if(a[ll]<a[rr])printf("%c",a[l++]);else if(a[ll]>a[rr])printf("%c",a[r--]);}num++;if(num%80==0)printf("\n");}if(num%80)printf("\n");return 0;}
- poj 3623 Best Cow Line, Gold (题意和3617一样只要代码中的范围改一下)
- 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
- 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 题目3623 Best Cow Line, Gold(后缀数组rank简单应用)
- P2870 (poj 3617) [USACO07DEC]最佳牛线,黄金Best Cow Line, Gold 可爱的贪心
- PKU 3623 Best Cow Line, Gold
- poj3623 Best Cow Line, Gold(贪心)
- POJ3623 Best Cow Line,Gold
- POJ3623-Best Cow Line, Gold
- java的学习记录6
- map用法
- [快捷工具] windows下批量删除空目录的简单方法
- 吉林大学2013级大一下学期程序设计作业:同学通讯录系统
- matlab中记录程序运行时间
- poj 3623 Best Cow Line, Gold (题意和3617一样只要代码中的范围改一下)
- Java Web开发Basic(四) JSON
- 冒泡算法
- web.xml 中的listener、 filter、servlet 加载顺序及其详解
- js 解析json
- 碰撞检测
- [转]Linux下C开发——gcc,gdb的使用
- div漂亮样式
- 虚拟机网络连接模式