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. 【.net ajax显示后台返回值】

    1..net ajax显示后台返回值 <script>        $(document).ready(function () {            $("#btn&quo ...

  2. VERY DEEP CONVOLUTIONAL NETWORKS FOR LARGE-SCALE IMAGE RECOGNTION(翻译)

    0 - ABSTRACT 在这个工作中,我们研究了卷积网络的深度对于它在大规模图像识别设置上的准确率的效果.我们的主要贡献是对使用非常小的卷积核(3×3)来增加深度的网络架构进行彻底评估,这说明了通过 ...

  3. Maven入门项目创建

    项目构建 1.新建maven项目 2.跳过骨架选择,如果不跳过骨架选择创建出的项目目录是不全的(骨架其实就是项目的模板) 3.Group Id,Artifact Id,Version称为项目的坐标,当 ...

  4. Dotest-两张图告诉你,为什么要测试兼容性?

     这就是为什么要测试兼容性的原因:如下图:一个是IE浏览器.一个是Google浏览器

  5. openstack Q版部署-----界面horizon安装(9)

    一.界面的安装 控制节点安装软件包: yum install openstack-dashboard -y [root@linux-node1 ~]# vim /etc/openstack-dashb ...

  6. 拦截RESTful API并做相应处理的方式

    ⒈使用Filter(过滤器) package cn.coreqi.security.filter; import org.springframework.stereotype.Component; i ...

  7. 使用Office Online Server在线预览Office

    微软官方文档介绍 ⒈介绍 Office Online Server是 Office Web Apps Server 的升级版本,安装环境必须为两台Windows Server 2012 R2 或 Wi ...

  8. 【转】数据库介绍(MySQL安装 体系结构、基本管理)

    [转]数据库介绍(MySQL安装 体系结构.基本管理) 第1章 数据库介绍及mysql安装 1.1 数据库简介 数据库,简而言之可视为电子化的文件柜——存储电子文件的处所,用户可以对文件中的数据运行新 ...

  9. xv6 + Qemu 在Ubuntu下编译运行教程【转】

    转自:https://blog.csdn.net/yinglang19941010/article/details/49310111 如果想要离线看教程,可以下载该 文档 一.使用工具说明 1.    ...

  10. Django:前后端分离后联调给前端传数据

    实现前后端分离后,有了下面几点改变: 1.服务器一分为二,前后端分别部署,静态资源放在前端服务器,业务代码放在后的服务器 2.前端服务器需要接收Http请求(一般使用node.js) 3.前端服务器需 ...