大致题意:
给你一个字符串,现在要生成一个新的字符串,规则是每次从原字符串的头部或者尾部取一个字符放在新字符串的尾巴上。求字典序最小的新字符串。
大致思路:
正解是后缀数组,这里用贪心水过去了。
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
const int nMax=30005;
char str[nMax];
bool check(int a,int b){
while(a<b){
if(str[a]>str[b])return 1;
if(str[a]<str[b])return 0;
a++;
b--;
}
return 0;
}
int main(){
int n,i,j,head,tail;
while(scanf("%d",&n)!=EOF){
int cnt=0;
head=0,tail=n-1;
for(i=0;i<n;i++){
cin>>str[i];
}
while(head<=tail){
if(check(head,tail)==0){
printf("%c",str[head]);
cnt++;
head++;
}
else{
printf("%c",str[tail]);
cnt++;
tail--;
}
if(!(cnt%80))
printf("\n");
}
if(cnt%80)
printf("\n");
}
return 0;
}
分享到:
相关推荐
poj 3623 Best Cow Line, Gold.md
北大POJ3267-The Cow Lexicon
北大POJ3267-The Cow Lexicon 解题报告+AC代码
NULL 博文链接:https://128kj.iteye.com/blog/1754756
北大POJ3176-Cow Bowling
北大POJ3278-Catch That Cow 解题报告+AC代码
这是西北工业大学的POJ试题的答案,欢迎下载!
搜索......................................................
北大POJ3176-Cow Bowling 解题报告+AC代码
poj 1989 The Cow Lineup.md
网上整理的一些poj刷题指南。 poj地址:http://poj.org
poj 3266 Cow School.md
POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类
NULL 博文链接:https://128kj.iteye.com/blog/1759266
poj1087贪心算法实验报告 poj1087贪心算法实验报告
北大POJ3274-Gold Balanced Lineup 解题报告+AC代码
poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题...
twilight-poj-solutionPOJ () solution by twilight想当年要找一题的分析, 解答实在太难了现在都是开源的时代了, 干脆把Archive放到GitHub上, 供后来人参考.POJ ID: 部分题解: 转载请注明出处~
poj 算法题在poj.org上做的一些算法题poj.org 账号:xxfeixiang题目地址:例如,第1001题的地址为:
POJ 3267 POJ 1260 POJ 1015 POJ 3176 POJ 1080 POJ 1159 POJ 2533 POJ 1836 Leetcode 70 Leetcode 309 搜索 DFS POJ 2488 POJ 3083 POJ 3009 POJ 1321 BFS POJ 3278 POJ 1426 POJ 3126 POJ 3414 POJ 2251 简单搜索...