POJ 3617 Best Cow Line (基础贪心)
来源:互联网 发布:知乎电动汽车书籍 编辑:程序博客网 时间:2024/05/17 23:52
题目链接:点击打开链接
贪心策略为不断检测串S的首尾元素,选取小的一方输出
当然如果两端相等就判断下一个,一直到两端相遇,此时默认输出左边(反正都一样)
当然有一个每行80个字符的坑(日常PE
AC代码如下:
#include <iostream>#include <cstring>#include <vector>using namespace std;int main(){ vector<char> S; int N; while(cin>>N) { S.clear(); for(int i=1; i<=N; ++i) { char c; cin>>c; S.push_back(c); } int head = 0, nail = N-1; vector<char> T; T.clear(); while(head<=nail) { int flag = 1; for(int i=0; head+i<=nail; ++i) { if(S[head+i]<S[nail-i]) { flag=1; break; } else if(S[head+i]>S[nail-i]) { flag=0; break;} } if(flag) T.push_back(S[head++]); else T.push_back(S[nail--]); } for(int i=1;i<=N;++i) { if(i%80==0) cout<<T[i-1]<<endl; else cout<<T[i-1]; } cout<<'\n'; } return 0;}
阅读全文
0 0
- 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 3617Best 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(贪心)
- 蓝桥杯题_ALGO11_瓷砖铺放
- 营销型图片不可缺少的因素
- HDU 6143 Killer Names(dp+容斥)
- JavaScript 原型的理解
- ios-NSURLSession
- POJ 3617 Best Cow Line (基础贪心)
- [python]python必学的五个包
- 一种修正观测分布的迭代算法
- 学习webpack中存在的问题
- MyEclipse10搭建Strust2开发环境
- 蚍蜉叹
- SchemaManagementException----异常一只
- HDU 6133 Army Formations(2017 Multi-University Training Contest 8)
- svg个人小结