当前位置:网站首页>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
边栏推荐
- [玩转Linux] [Docker] MySQL安装和配置
- Hudi vs Delta vs Iceberg
- 如何自定义动漫头像?这6个免费精品在线卡通头像生成器,看一眼就怦然心动!
- How to do smoke test
- 企业精益管理体系介绍
- Low CPU load and high loadavg processing method
- Druid database connection pool details
- How to customize animation avatars? These six free online cartoon avatar generators are exciting at a glance!
- Classic 100 questions of algorithm interview, the latest career planning of Android programmers
- Yyds dry goods inventory leetcode question set 751 - 760
猜你喜欢
随机推荐
Cf960g - bandit Blues (type I Stirling number +ogf)
深入分析,Android面试真题解析火爆全网
社招面试心得,2022最新Android高频精选面试题分享
在解决了 2961 个用户反馈后,我做出了这样的改变...
从sparse.csc.csr_matrix生成邻接矩阵
After solving 2961 user feedback, I made such a change
MySQL information schema learning (II) -- InnoDB table
MATLAB中deg2rad和rad2deg函数的使用
Introduction to enterprise lean management system
10 schemes to ensure interface data security
An error occurs when installing MySQL: could not create or access the registry key needed for the
测试用里hi
350. 两个数组的交集 II
C # use Marshall to manually create unmanaged memory in the heap and use
zabbix 代理服务器 与 zabbix-snmp 监控
How can my Haskell program or library find its version number- How can my Haskell program or library find its version number?
Druid 数据库连接池 详解
A5000 vGPU显示模式切换
[infrastructure] deployment and configuration of Flink / Flink CDC (MySQL / es)
接雨水问题解析