pku 3617 - Best Cow Line
来源:互联网 发布:体检软件哪个好 编辑:程序博客网 时间:2024/06/10 11:55
題目:已知串S和空串T,每次從S的兩端中去一個字符放入T的尾部,求T的最小字典序。
分析:貪心。每次雙向掃描,取字典序小的字串方向的字符。
說明:不能直接比較兩端字符,反例DCCEAAD。
#include <cstdio>char S[2002];int main(){int n;while (~scanf("%d",&n)) {getchar();for (int i = 0; i < n; ++ i) {scanf("%c",&S[i]);getchar();}int l = 0, r = n-1, count = 0;while (l <= r) {int left = 0;for (int i = 0; l+i <= r; ++ i) {if (S[l+i] < S[r-i]) {left = 1;break;}else if (S[l+i] > S[r-i]) {break;}}if (left) {putchar(S[l ++]);}else {putchar(S[r --]);}if ((++ count)%80 == 0) {putchar('\n');}}if (count%80) {putchar('\n');}}return 0;}
0 0
- pku 3617 - Best Cow Line
- PKU 3617 Best Cow Line和PKU 3623 Best Cow Line 解题报告
- Pku oj 3617 Best Cow Line(贪心)
- PKU 3623 Best Cow Line, Gold
- POJ-3617-Best Cow Line
- POJ 3617 Best Cow Line
- POJ:3617 Best Cow Line
- POJ 3617 Best Cow Line
- POJ-3617 Best Cow Line
- poj 3617 Best Cow Line
- poj 3617 Best Cow Line
- POJ 3617 Best Cow Line
- POJ 3617 Best Cow Line
- POJ 3617 Best Cow line
- POJ Best Cow Line 3617
- POJ 3617 Best Cow Line
- Best Cow Line(POJ-3617)
- POJ 3617 Best Cow Line
- Oracle Data Access Components (ODAC)
- NPAPI & NPRuntime 簡介 Scriptable Plugin
- 对IntentService的几点看法
- Servlet概述
- IntentService与Service的区别
- pku 3617 - Best Cow Line
- [RaspberryPi] 树莓派初体验 - 无线网络设置与VNC连接
- 324. Wiggle Sort II
- HTTP Client
- Permutation Sequence
- HTTP Url
- 临界资源 & 临界区
- Linux网络安全策略
- Eclipse_Debug 界面应用详解——Eclipse Debug不为人知的秘密