Follow me 挑战程序与设计
来源:互联网 发布:天猫实时大数据 编辑:程序博客网 时间:2024/06/16 19:56
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 theith 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
每八十个字符换一行!!!
做一只打不死,拖不跨的小强
#include <cstdio>#include <algorithm>#include <iostream>#define MAX 2009using namespace std;string A;char a[MAX];bool dp(int x,int y)//因为有可能出现首字符与末尾字符相等的情况,所以要不断判断直到出现不相等的情况{ if (a[x]==a[y]) { return dp(x+1,y-1); } if (a[x]<=a[y]) return true; else return false;}int main(){ int N; cin>>N;for (int i=0;i<N;i++) { cin>>a[i]; } int left=0,right=N-1,sum=0;while(sum<N) { if (a[left]<a[right]) { A+=a[left]; left++; } else if (a[left]>a[right]) { A+=a[right]; right--; } else if (a[left]==a[right]) { if (dp(left,right)) { A+=a[left]; left++; } else { A+=a[right]; right--; } } sum++; } int temp=0; for (int i=0;i<A.size();i++) { cout<<A[i]; temp++; if (temp==80) { temp=0; cout<<endl; } } return 0;}
- Follow me 挑战程序与设计
- Follow me 挑战程序与设计
- Follow me 挑战程序与设计
- Follow me 挑战程序与设计
- Follow me--挑战程序与设计
- Follow me--挑战程序与设计
- follow me
- Follow me on Twitter !
- Follow Me: ArcPy(1)
- Follow Me: ArcPy(2)
- mongodb CURD follow me
- 加壳程序CPU-FOLLOW ME测试版(含源码)已经发布
- Objective-C 学习Follow Me(一)
- Python挑战第四关follow the chain
- 软件项目管理Follow Me--如何进行项目估算
- 项目管理Follow Me – MS Project使用经验谈
- Follow Me:深入浅出学习Hibernate一:Hibernate概述
- Follow Me:深入浅出学习Hibernate二:Hibernate第一实例
- CodeForces
- 有关Java Collections的几个常见问题
- sql优化
- Latex使用小结(1)
- Quartz定时调度框架
- Follow me 挑战程序与设计
- spring源码解析之二(究竟从哪个入手)
- Java SE/EE是啥,ssh等框架是用来干嘛的
- protected-broadcast 规范使用系统应用组件自定义广播
- hud 1428 漫步校园 优先队列+记忆化搜索
- 进程调度时机与进程切换分析
- 利用Anaconda简单安装scrapy框架
- CodeForces
- 并查集的优化措施