POJ3617 Best Cow Line
来源:互联网 发布:csgo低配置优化 编辑:程序博客网 时间:2024/06/05 16:19
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<stdio.h>#include<string.h>#include<iostream>#include<algorithm>#include<vector>using namespace std;int main(){ vector<char> pr; vector<char>::iterator it; vector<char>::iterator is; vector<char>::iterator en; int i,t,n,r,m,x,a; while(scanf("%d",&n)!=EOF){ a=0;m=0; getchar(); pr.clear(); for(i=0;i<n;i++){ scanf("%c",&x); getchar(); pr.push_back(x); } while(1){ it=pr.begin(); is=it+1; en=pr.end(); en--; t=pr.size(); if(t==1){ printf("%c",*it); break; } else if(*it<*en) { printf("%c",*it); m++; pr.erase(it,is); }else if(*it>*en){ printf("%c",*en); m++; pr.pop_back(); }else{ a=0; for(i=1;i<=t/2;i++){ if(*(it+i)>*(en-i)){ a=1;break; }else if(*(it+i)<*(en-i)){ a=2;break; } } if(a==1){ printf("%c",*en); m++; pr.pop_back(); }else{ printf("%c",*it); m++; pr.erase(it,is); } } if(m==80){ m=0; printf("\n"); } } if(m) printf("\n"); } return 0;}
- POJ3617 Best Cow Line
- POJ3617 Best Cow Line
- POJ3617 Best Cow Line
- best cow line(poj3617)
- POJ3617-Best Cow Line
- POJ3617 Best Cow Line
- POJ3617 Best Cow Line
- poj3617 Best Cow Line
- POJ3617 Best Cow Line
- POJ3617-Best Cow Line
- poj3617 Best Cow Line
- poj3617 Best Cow Line
- POJ3617 Best Cow Line
- POJ3617 Best Cow Line
- poj3617 Best Cow Line 贪心
- POJ3617 Best Cow Line 贪心
- poj3617 Best Cow Line 贪心
- poj3617 Best Cow Line 贪心
- 变化检测的基础算法与实现
- 企业级zabbix详解
- Java总结第三章
- 1.引用 / typedef /enum
- VHDL:conv_std_logic_vector的用法
- POJ3617 Best Cow Line
- 用cuda实现向量点乘
- CCF 1037 个位数
- Python版飞机大战
- UVA
- UnsupportedOperationException之Collections$UnmodifiableList异常
- python学习手册(第四章:介绍python对象类型)
- unityShader之CG标准函数库
- [zjoi2016][小星星][容斥]解题报告