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. PhpStorm+xdebug+postman调试

    PhpStorm+xdebug+postman调试 写PHP时,一直用postman做测试,最近发现在测试过程中可以用xdebug来断点调试,比原来手动打exit或者die来断点效率高多了. 下面记录 ...

  2. 非关系型数据库mongodb的语法模式

    from pymongo import MongoClient #连接 conn = MongoClient() #进入数据库 db = conn.edianzu #连接mydb数据库,没有则自动创建 ...

  3. ES6走一波 变量结构赋值

    Destructuring  变量的解构赋值 是一种模式匹配 ES6我关注点之一是用途  能否举些好例子是检验学习到位的方法之一 交换变量值 函数返回多个值 函数入参为对象.数组,内部使用更简洁 意义 ...

  4. vue-CLI踩坑记

    vue init webpack vue-demo 使用 windows 7 DOS命令行和gitbash都有选择和实际选择结果不一致的问题, DOS命令行只在 Vue build有问题, gitba ...

  5. Spring中@Transactional(rollbackFor = Exception.class)的作用

    Spring中的@Transactional(rollbackFor = Exception.class)事务处理,当你的方法中抛出异常时,它会将 事务回滚,数据库中的数据将不会改变,也就是回到进入此 ...

  6. Spring如何支持可扩展

    Spring是一款优秀的开发框架,包括了非常多的基础组件 那么它是如何做到灵活可扩展呢? 1 .框架初始化 2.Bean初始化 ref https://mp.weixin.qq.com/s/QuSls ...

  7. burp导入证书后仍然抓不到https包

    burp导入证书后仍然抓不到https包 如果你是导入证书有问题,请参考此博客 http://blog.csdn.net/zyw_anquan/article/details/47904495 有一点 ...

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

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

  9. nginx使用https协议

    效果: nginx添加ssl模块 ./configure --with-http_ssl_module 生成证书 openssl genrsa -out ca.key 2048 openssl req ...

  10. Python笔记 【无序】 【五】

    描述符 将某种特殊类型的类[只要实现了以下或其中一个]的实例指派给另一个类的属性 1.__get__(self,instance,owner)//访问属性,返回属性的值 2.__set__(self, ...