Best Cow Line(POJ3617)
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)的更多相关文章
- POJ 3617 Best Cow Line (贪心)
Best Cow Line Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16104 Accepted: 4 ...
- 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 ...
- POJ 3268 Silver Cow Party (最短路径)
POJ 3268 Silver Cow Party (最短路径) Description One cow from each of N farms (1 ≤ N ≤ 1000) convenientl ...
- Poj 3613 Cow Relays (图论)
Poj 3613 Cow Relays (图论) 题目大意 给出一个无向图,T条边,给出N,S,E,求S到E经过N条边的最短路径长度 理论上讲就是给了有n条边限制的最短路 solution 最一开始想 ...
- poj3617 best cow line(贪心题)
Best Cow Line Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 32687 Accepted: 8660 De ...
- POJ 3617 Best Cow Line(最佳奶牛队伍)
POJ 3617 Best Cow Line Time Limit: 1000MS Memory Limit: 65536K [Description] [题目描述] FJ is about to t ...
- 【BZOJ】3301: [USACO2011 Feb] Cow Line(康托展开)
http://www.lydsy.com/JudgeOnline/problem.php?id=3301 其实这一题很早就a过了,但是那时候看题解写完也是似懂非懂的.... 听zyf神犇说是康托展开, ...
- POJ 3617:Best Cow Line(贪心,字典序)
Best Cow Line Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 30684 Accepted: 8185 De ...
- 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 ...
随机推荐
- jinja模板语法
模板 要了解jinja2,那么需要先理解模板的概念.模板在Python的web开发中广泛使用,它能够有效的将业务逻辑和页面逻辑分开,使代码可读性增强.并且更加容易理解和维护. 模板简单来说就是一个其中 ...
- LOJ #2196「SDOI2014」LIS
直接退流复杂度好优越啊 LOJ #2196 题意 一段数列,每个点有点权$ A_i$,删除代价$ B_i$,附加属性$ C_i$ 求最小代价使得$ LIS$长度发生变化,且输出一种$ C_i$字典序最 ...
- 算法 - 链的操作(三) - 返回倒数第k个节点(no.23)
输入一个链 : 1 -> 3 -> 5 -> 6 -> 8 输入 k = 2 返回 6 这个节点 python(2.7) def getNode(head, k): if(h ...
- IDEA 启动项目前的配置--或过程遇到的问题
配置JDK 配置Maven路径和 仓库路径:文件->设置 配置Tomcat Server 文件-->设置 运行时 选择一个tomcat服务器 ==拓展: 本人台式机 的2016版本,因汉 ...
- Django中的信号基础知识
Django中提供了“信号调度”,用于在框架执行操作时解耦.通俗来讲,就是一些动作发生的时候,信号允许特定的发送者去提醒一些接受者. 1.Django内置信号 1 2 3 4 5 6 7 8 9 10 ...
- 安装mysql8.0.12以及修改密码和Navicat的连接
mysql8.0+与安装其他版本不同一.安装mysql8.0.121.到官网https://www.mysql.com/ 下载mysql-8.0.12-winx64.zip(不要.mis),直接解压 ...
- Latex 编辑数学公式——快速上手
参考链接: https://blog.csdn.net/fansongy/article/details/45368915 特殊符号: https://blog.csdn.net/caiandyong ...
- 20165231 预备作业二:学习基础和C语言基础调查
微信文章感想 读了娄老师微信公众号中的文章,老师给我们的启示首先就是要坚持,万事开头难,但是只要肯坚持就一定会有所成就,不管是学习还是生活方面.其中最有触动的就是减肥了,是我三四年来一直难以完成的目标 ...
- Keepalived+LVS-DR+Nginx高可用故障切换模式
LVS架构中,不管是NAT模式还是DR模式,当后端的RS宕掉后,调度器依然会把请求转发到宕掉的RS上,这样的结果并不是我们想要的.其实,keepalived就可以解决问题,它不仅仅有高可用的功能,还有 ...
- 2018牛客暑期ACM多校训练营第二场(有坑未填)
第二场终于等来学弟 开始(被队友带飞)的开心(被虐)多校之旅 A run A题是一个递推(dp?)+前缀和 因为看数据量比较大 就直接上前缀和了 一个比较简单的递推 没有太多难点 签到题 需要注意 ...