POJ3617 字典序最小问题
来源:互联网 发布:广发淘宝卡金卡和普卡 编辑:程序博客网 时间:2024/05/16 14:35
<span style="font-size: 18pt; widows: auto; font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">Best Cow Line</span>
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
6ACDBCB
Sample Output
ABCBCD
Source
#include <iostream>#include <stdio.h>using namespace std;int N = 6;char S[6] = {'A','C','D','B','C','B'};void solve(){int a = 0,b = N-1;while(a<=b){bool left = false;for (int i = 0; i+a <= b; i++){if (S[a+i] < S[b]){left = true;break;}else if (S[a+i] > S[b]){left = false;break;}}if (left){putchar(S[a++]);}else{putchar(S[b--]);}}printf("\n");}int main(){ solve(); cout << "Hello world!" << endl; return 0;}
- POJ3617(字典序最小问题)
- poj3617(字典序最小问题)
- POJ3617 字典序最小问题
- 贪心字典序最小问题poj3617
- 字典序最小问题 前后删除加入 贪心poj3617
- POJ3617 Best Cow Line (字典序最小问题)
- 字典序最小问题-贪心-Best Cow Line-POJ3617
- poj3617字典序问题【贪心】
- poj3617 生成字典序最小字符串
- POJ3617 Best Cow Line(贪心,字典序最小)
- 贪心专练2 最小字典序排序POJ3617
- POJ3617-贪心字典序 水
- 【OJ】贪心法(最小字典序)poj3617 Best Cow Line// acmclub 12701/12695
- 字典序最小问题
- 字典序最小问题
- 字典序最小问题
- 字典序最小问题
- 字典序最小问题
- 笔试题:数据库 (1)
- centos系统安装nod32杀毒软件并通过xmanager进行远程管理
- 从简单Sql探索优化之道
- PHP数据类型转换与常量的使用
- vs无法生成exe文件
- POJ3617 字典序最小问题
- 中文截取函数
- flume学习
- Android TextView自定义实现@用户跳转
- VBA,iLogic,插件中使用学徒服务器
- 进程与线程的区别与联系(经典面试题)
- Unity PoolManager
- 过拟合与欠拟合问题
- 博客地址更换