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

6
A
C
D
B
C
B

Sample Output

ABCBCD
//刚开始没看到要80个字母换行一次,导致一直是格式错误,也是醉了,大佬的又一次复制;
 #include<iostream>
#include<string>
#include<cstring>
using namespace std;
int main()
{
char aa[];
int n;
cin >> n;
for (int i = ; i < n; i++)
cin >> aa[i];
int a = , b = n - ,mark =;
while (a <= b)
{
bool left = false;
for (int i = ; a + i <= b; i++)
{
if (aa[a + i] < aa[b - i])
{
left = true;
mark++;
break;
}
else if (aa[a + i] > aa[b - i])
{
left = false;
mark++;
break;
}
}
if (left) cout << aa[a++];
else cout << aa[b--];
if (mark % == )cout << endl;
}
putchar('\n');
return ;
}

这次的大佬代码让我明白的原来输出可以这样弄,酷

Best Cow Line(POJ3617)的更多相关文章

  1. POJ 3617 Best Cow Line (贪心)

    Best Cow Line   Time Limit: 1000MS      Memory Limit: 65536K Total Submissions: 16104    Accepted: 4 ...

  2. POJ 3617 Best Cow Line (模拟)

    题目链接 Description FJ is about to take his N (1 ≤ N ≤ 2,000) cows to the annual"Farmer of the Yea ...

  3. POJ 3268 Silver Cow Party (最短路径)

    POJ 3268 Silver Cow Party (最短路径) Description One cow from each of N farms (1 ≤ N ≤ 1000) convenientl ...

  4. Poj 3613 Cow Relays (图论)

    Poj 3613 Cow Relays (图论) 题目大意 给出一个无向图,T条边,给出N,S,E,求S到E经过N条边的最短路径长度 理论上讲就是给了有n条边限制的最短路 solution 最一开始想 ...

  5. poj3617 best cow line(贪心题)

    Best Cow Line Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 32687   Accepted: 8660 De ...

  6. POJ 3617 Best Cow Line(最佳奶牛队伍)

    POJ 3617 Best Cow Line Time Limit: 1000MS Memory Limit: 65536K [Description] [题目描述] FJ is about to t ...

  7. 【BZOJ】3301: [USACO2011 Feb] Cow Line(康托展开)

    http://www.lydsy.com/JudgeOnline/problem.php?id=3301 其实这一题很早就a过了,但是那时候看题解写完也是似懂非懂的.... 听zyf神犇说是康托展开, ...

  8. POJ 3617:Best Cow Line(贪心,字典序)

    Best Cow Line Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 30684   Accepted: 8185 De ...

  9. codeforces 319B Psychos in a Line(模拟)

    There are n psychos standing in a line. Each psycho is assigned a unique integer from 1 to n. At eac ...

随机推荐

  1. Linux下运行jmeter

    • 我们在做测试的时候,有时候要运行很久,公司用的测试服务器一般都是linux,就可以运行在linux下面,linux下面不能像windows一样有图形化界面,那怎么运行脚本呢,就先在windows上 ...

  2. Java基础_0305:简单Java类

    简单Java类 简单Java类是一种在实际开发之中使用最多的类的定义形式,在简单Java类中包含有类.对象.构造方法.private封装等核心概念的使用,而对于简单Java类首先给出如下的基本开发要求 ...

  3. python基础类知识~pymysql封装类

    一简介:咱们来介绍下 DBA常用的几个类 二 具体代码 #!/usr/bin/python3import pymysqlimport sysclass DBHelper: def __init__(s ...

  4. 20165234 《Java程序设计》第二周学习总结

    第二周学习总结 教材学习内容总结 第二章 标识符与关键字 1.标识符 其本质是文件名字. 由字母.下画线.美元符号和数字组成,长度不受限制. 标识符的第一个字符不能为数字,标识符不能为关键字(如int ...

  5. 阿里云上 配置 vsftpd 配置文件 (一个成功例子)

    # # READ THIS: This example file is NOT an exhaustive list of vsftpd options. # Please read the vsft ...

  6. Idea实用配置

    参考:https://github.com/judasn/IntelliJ-IDEA-Tutorial 1.代码提示不区分大小写 2.跳到指定行 Ctrl + G Ctrl 快捷键 介绍 Ctrl + ...

  7. Java基础5-接口

    昨日内容回顾 jvm参数设置 -Xmx //设置最大堆大小 java -Xmx512m Classname -Xms //设置初始堆大小 java -Xms24m Classname -Xss //设 ...

  8. shell 在手分析服务器日志【转】

    自己的小网站跑在阿里云的 ECS 上面, 偶尔也去分析分析自己网站服务器日志,看看网站的访问量.看看有没有黑阔搞破坏!于是收集,整理一些服务器日志分析命令,大家可以试试! awk '{print $1 ...

  9. python字典不区分大小写

    from multidict import CIMultiDict dic=CIMultiDict() dic["key"]="1234" print(dic[ ...

  10. linux批量替换文件内容3种方法(perl,sed,shell)

    方法1:perl   这两天在构建一个应用的使用用到了maven,由于project很大,足足有700多个 pom.xml文件,更郁闷的是在很多pom.xml文件里都单独指定了资源库的url,我需要把 ...