当前位置:网站首页>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
边栏推荐
- Interview assault 63: how to remove duplication in MySQL?
- ZABBIX proxy server and ZABBIX SNMP monitoring
- 【pytorch】yolov5 训练自己的数据集
- 【翻译】云原生观察能力微调查。普罗米修斯引领潮流,但要了解系统的健康状况仍有障碍...
- Learning and Exploration - Seamless rotation map
- PMP practice once a day | don't get lost in the exam -7.6
- How to access localhost:8000 by mobile phone
- 黑马--Redis篇
- IC设计流程中需要使用到的文件
- Alibaba data source Druid visual monitoring configuration
猜你喜欢

Introduction to enterprise lean management system

黑马--Redis篇

力扣101题:对称二叉树

VMware virtual machine cannot open the kernel device "\.\global\vmx86"

Microservice architecture debate between radical technologists vs Project conservatives

Mysql Information Schema 学习(一)--通用表

Mind map + source code + Notes + project, ByteDance + JD +360+ Netease interview question sorting

Mysql Information Schema 學習(一)--通用錶

企业精益管理体系介绍

Phoenix Architecture 3 - transaction processing
随机推荐
终于可以一行代码也不用改了!ShardingSphere 原生驱动问世
How to do smoke test
Analysis of rainwater connection
Application of clock wheel in RPC
How to access localhost:8000 by mobile phone
Chic Lang: attributeerror: partially initialized module 'CV2' has no attribute 'GAPI_ wip_ gst_ GStreamerPipe
Excel 中VBA脚本的简单应用
Yyds dry goods inventory leetcode question set 751 - 760
350. 两个数组的交集 II
【翻译】云原生观察能力微调查。普罗米修斯引领潮流,但要了解系统的健康状况仍有障碍...
Mysql Information Schema 学习(一)--通用表
Systematic and detailed explanation of redis operation hash type data (with source code analysis and test results)
潇洒郎: AttributeError: partially initialized module ‘cv2‘ has no attribute ‘gapi_wip_gst_GStreamerPipe
Hudi vs Delta vs Iceberg
Swiftui game source code Encyclopedia of Snake game based on geometryreader and preference
Use of deg2rad and rad2deg functions in MATLAB
Classic 100 questions of algorithm interview, the latest career planning of Android programmers
今日直播 | “人玑协同 未来已来”2022弘玑生态伙伴大会蓄势待发
Leetcode 30. 串联所有单词的子串
short i =1; I=i+1 and short i=1; Difference of i+=1