Best Cow Line

Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 42701   Accepted: 10911

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

题意:输入n个大写字母组成一个字符串S,每次可以从这个字符串的队首或队尾取一个字符加到字符串T中(T初始为空),
输出字典序最小的T,当T的长度等于80时输出一个换行
#include<iostream>
#include<string.h>
#include<string>
#include<algorithm>
#include<queue>
#include<set>
using namespace std;
string s,t;
char x;
int n;
int main()
{
cin>>n;
int temp=n;
while(temp--)
{
cin>>x;
s=s+x;
}
int l=,r=n-,cnt=;
while(l<=r)
{
int flag=;
for(int i=;i<=r-l;i++)
{
if(s[l+i]<s[r-i])
{
flag=;//输出左边
cnt++;
break;
}
else if(s[l+i]>s[r-i])
{
flag=;//输出右边
cnt++;
break;
}
else
{
continue;//相等,比较下一个
}
}
if(flag==)
{
cout<<s[l];
l++;
}
else
{
cout<<s[r];
r--;
}
if(cnt%==)
cout<<endl;
}
cout<<endl;
return ;
}
												

poj 3617 Best Cow Line 贪心模拟的更多相关文章

  1. POJ 3617 Best Cow Line 贪心算法

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

  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 3617 Best Cow Line (贪心)

    题意:给定一行字符串,让你把它变成字典序最短,方法只有两种,要么从头部拿一个字符,要么从尾部拿一个. 析:贪心,从两边拿时,哪个小先拿哪个,如果一样,接着往下比较,要么比到字符不一样,要么比完,也就是 ...

  4. POJ 3617 Best Cow Line ||POJ 3069 Saruman's Army贪心

    带来两题贪心算法的题. 1.给定长度为N的字符串S,要构造一个长度为N的字符串T.起初,T是一个空串,随后反复进行下面两个操作:1.从S的头部删除一个字符,加到T的尾部.2.从S的尾部删除一个字符,加 ...

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

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

  6. POJ 3617 Best Cow Line (贪心)

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

  7. poj 3617 Best Cow Line (字符串反转贪心算法)

    Best Cow Line Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9284   Accepted: 2826 Des ...

  8. POJ 3617 Best Cow Line (字典序最小问题 & 贪心)

    原题链接:http://poj.org/problem?id=3617 问题梗概:给定长度为 的字符串 , 要构造一个长度为 的字符串 .起初, 是一个空串,随后反复进行下列任意操作. 从 的头部删除 ...

  9. poj 3617 Best Cow Line

    http://poj.org/problem;jsessionid=F0726AFA441F19BA381A2C946BA81F07?id=3617 Description FJ is about t ...

随机推荐

  1. 获取 AppStore 中 应用 的 IPA 包文件(Mac OS 13+)

    在 Mac OS 12.7 之前,可以通过 iTunes 直接下载 App Store 中应用的 IPA 包,可以提取其他应用的资源图片,查看信息等操作.之后 苹果 公司禁用了这一功能,不能直接通过 ...

  2. LinkQueue(链队)

    今天学习了队列,因为前面写了好几个链表实现的数据结构基本上都懂了,然后大致了解了一下队列的特点,便决定用自己的理解来实现一个,然后实现了. (2018-02-14 代码更新) Head file: # ...

  3. Mysql 连接时的 option 含义

    官网文档: https://dev.mysql.com/doc/refman/5.7/en/mysql-real-connect.html

  4. 「JSOI2011」柠檬

    「JSOI2011」柠檬 传送门 斜率优化题. 在优化前,还有一个值得一提的优化: 对于最后的最优分割方案,每一段的两个端点一定是同颜色的,并且作为这一段的 \(s_0\) 证明:如果不作为这一段的 ...

  5. centos 默认php 版本太低移到高版本的办法

    // centos 默认有php 版本太低转移到高版本的解决办法 php -v 版本低 ln -s /usr/local/php/bin/php /usr/bin/php

  6. Android抓包分析-fiddler版

    本文介绍的是如何使用Fiddler工具抓取Android应用的HTTP协议的数据包 工具 Genymotion模拟器 笔记本电脑一台(Win7) Fiddler(v4.6.2),下载地址:http:/ ...

  7. checkbox 选中获取值

    1:jsp 页面 从页面获取checkbox 的值传到后台 <div id="divCheckbox" class="hide"> <tr&g ...

  8. 分析配置DispatcherServlet类时load-on-startup标签作用

    <servlet> <servlet-name>DispatcherServlet</servlet-name> <servlet-class>org. ...

  9. axios发送post请求node服务器无法通过req.body获取参数

    问题: 项目前端使用Vue框架,后端使用node.js搭建本地服务器.前端通过 axios 方式请求后端数据的过程中,发现如果是 get 请求,服务器端能够通过 req.query 获取前端传递的参数 ...

  10. 吴裕雄 Bootstrap 前端框架开发——Bootstrap 表单:表单帮助文本

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...