当前位置:网站首页>POJ3617 Best Cow Line 馋
POJ3617 Best Cow Line 馋
2022-07-06 11:47:00 【全栈程序员站长】
大家好,又见面了,我是全栈君。
虽然这个问题很简单,但非常好,由于过程是很不错的。发展思路的比较 并鼓励人们,不像有些贪心太偏,推动穷人,但恼人
鉴于长N弦S,然后又空字符串STR。每当有两个选择 1:删S增加虚假的第一要素STR于 2:删S增加最后一个元素STR于
是的STR字典序最小 并输出
開始可能没有什么顾虑的去想 每次比較S的头和尾元素 取小的那个删除并假如STR中。可是若S的头和尾元素一样的话这种方法就不行了,由于先取头或者尾还得看他们之间的元素,这时候是倒着来还是顺着好呢?那就直接拿顺的跟倒的进行字典序的大小比較就好了,这样当头尾相等时就能把他们中间的囊括进去,
做法:
字符串S。然后倒置得到S1,比較大小若S小,则取S的头部元素。若S大则取S的尾部元素,然后再把S倒置。再与它的倒置比較,如此循环的做N次就可以
#include<iostream>
#include<cstdio>
#include<list>
#include<algorithm>
#include<cstring>
#include<string>
#include<queue>
#include<stack>
#include<map>
#include<vector>
#include<cmath>
#include<memory.h>
#include<set>
#include<cctype>
#define ll long long
#define LL __int64
#define eps 1e-8
#define inf 0xfffffff
//const LL INF = 1LL<<61;
using namespace std;
//vector<pair<int,int> > G;
//typedef pair<int,int > P;
//vector<pair<int,int> > ::iterator iter;
//
//map<ll,int >mp;
//map<ll,int >::iterator p;
string s;
string str;
string ans;
string ch;
int main() {
int n;
bool flag = false;
while(cin>>n) {
while(n--) {
cin>>ch;
s += ch;
}
str = s;
reverse(s.begin(),s.end());
int len = s.length();
while(len--) {
if(str < s) {
ans += str[0];
str.erase(0,1);
}
else {
ans += str[str.length() - 1];
str.erase(str.length() - 1,1);
}
s = str;
reverse(s.begin(),s.end());
}
for(int i=0;i<ans.length();i++) {
cout<<ans[i];
if((i+1)%80 == 0)puts("");
}
puts("");
}
return 0;
}
版权声明:本文博客原创文章,博客,未经同意,不得转载。
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/117137.html原文链接:https://javaforall.cn
边栏推荐
- Dom 操作
- JDBC details
- Social recruitment interview experience, 2022 latest Android high-frequency selected interview questions sharing
- Microservice architecture debate between radical technologists vs Project conservatives
- Recursive implementation of department tree
- 在解决了 2961 个用户反馈后,我做出了这样的改变...
- C # use Marshall to manually create unmanaged memory in the heap and use
- 凤凰架构2——访问远程服务
- In simple terms, interview surprise Edition
- 今日直播 | “人玑协同 未来已来”2022弘玑生态伙伴大会蓄势待发
猜你喜欢
反射及在运用过程中出现的IllegalAccessException异常
Blue Bridge Cup microbial proliferation C language
A5000 vGPU显示模式切换
DaGAN论文解读
企业精益管理体系介绍
腾讯T3大牛手把手教你,大厂内部资料
Interview assault 63: how to remove duplication in MySQL?
In simple terms, interview surprise Edition
How to access localhost:8000 by mobile phone
Live broadcast today | the 2022 Hongji ecological partnership conference of "Renji collaboration has come" is ready to go
随机推荐
It's super detailed in history. It's too late for you to read this information if you want to find a job
MySQL information schema learning (I) -- general table
Introduction to enterprise lean management system
It's enough to read this article to analyze the principle in depth
终于可以一行代码也不用改了!ShardingSphere 原生驱动问世
测试用里hi
Phoenix Architecture 2 - accessing remote services
Swagger2 reports an error illegal DefaultValue null for parameter type integer
Alibaba data source Druid visual monitoring configuration
手把手教你学会js的原型与原型链,猴子都能看懂的教程
深入分析,Android面试真题解析火爆全网
学习探索-无缝轮播图
usb host 驱动 - UVC 掉包
Interview assault 63: how to remove duplication in MySQL?
学习探索-使用伪元素清除浮动元素造成的高度坍塌
Documents to be used in IC design process
系统性详解Redis操作Hash类型数据(带源码分析及测试结果)
spark基础-scala
Li Kou 101: symmetric binary tree
黑馬--Redis篇