Best Cow Line POJ
来源:互联网 发布:剑三苍云捏脸数据成女 编辑:程序博客网 时间:2024/06/04 23:34
题意: 告诉你一个长度为n的字符串,每次只能从头或者尾抽出一个字母。要你输出字典序(ASCLL码)最小的情况。
思路: 贪心,每次取,肯定取头和尾字典序最小的那个,但对于相同的情况,我们就要判断到底先取那个更有优势,那就要头和尾往中间查,查到哪个达到的比较小,那就是哪个了。
#include <cstdio>#include <iostream>using namespace std;const int maxn=2e3+500;char str[maxn];int cnt=0;int main(void){ int n; cin >> n; int a=0,b=n-1; for(int i=0;i<=n-1;i++) scanf("%s",str+i); //printf("%s\n",str); while(a<=b) { bool left=false; for(int i=0;a+i<=b;i++) { if(str[a+i]<str[b-i]) { left=true; break; } else if(str[a+i]>str[b-i]) { left=false; break; } else if(str[a+i]==str[b-i]) continue; } if(left) printf("%c",str[a++]); else printf("%c",str[b--]); cnt++; if(cnt==80) { printf("\n"); cnt=0; } }}
阅读全文
0 0
- poj Best Cow Line
- POJ-Best Cow Line
- Best Cow Line POJ
- Best Cow Line POJ
- POJ-3617-Best Cow Line
- POJ 3623 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)
- ZOJ 2795 Ambiguous permutations 水~
- BAT及各大互联网公司前端笔试面试题--Html,Css篇(加上自我整理总结哟)
- 欢迎使用CSDN-markdown编辑器
- C++Primer Plus(第六版) 第十二章 第二题
- HDU-2389 Rain on your Parade(二分图之Hopcroft-Karp算法)
- Best Cow Line POJ
- 我的服务器开发之路-安装mysql之mariadb并更改数据库路径
- CSS布局 position float
- tarjan(SCC)模板
- 15、链表中倒数第k个节点
- 【python技能】词频统计
- Django之Mode的外键自关联和引用未定义的Model
- CentOS 7 下开启Mysql-5.7.19远程访问
- 326. Power of Three