POJ 3617
?
題意:給定長度為N的字符串S,現要構造一個字符串T(起初為空串)。任意進行一下的一種操作:
1>從S的頭部刪除一個字符,加到T的尾部
2>從S的尾部刪除一個字符,加到T的尾部
目的使T的字典序最小。每80個字母一行
注意:當首尾倆個數相同時,我們應比較里面的倆個次首和次尾
1 #include <cstdio> 2 #include <cstring> 3 #include <cstdlib> 4 #include <cctype> 5 #include <cmath> 6 #include <time.h> 7 #include <string> 8 #include <map> 9 #include <stack> 10 #include <set> 11 #include <queue> 12 #include <vector> 13 #include <algorithm> 14 #include <iostream> 15 using namespace std; 16 typedef long long ll; 17 typedef pair<int,int> P; 18 #define PI acos( -1.0 ) 19 const double E = 1e-8; 20 21 const int NO = 2000 + 5; 22 char ch[NO]; 23 int n; 24 25 void Solve() 26 { 27 int x = 0, y = n - 1; 28 int t = 0; 29 while( x <= y ) 30 { 31 bool flag = false; 32 for( int i = 0; i < n; ++i ) 33 if( ch[x+i] > ch[y-i] ) { 34 flag = false; 35 break; 36 } 37 else if( ch[x+i] < ch[y-i] ) { 38 flag = true; 39 break; 40 } 41 ++t; 42 if( flag ) putchar( ch[x++] ); 43 else putchar( ch[y--] ); 44 if( t % 80 == 0 ) 45 putchar( '\n' ); 46 } 47 if( t % 80 ) 48 puts( "" ); 49 } 50 51 int main() 52 { 53 scanf( "%d", &n ); 54 for( int i = 0; i < n; ++i ) 55 { 56 getchar(); 57 ch[i] = getchar(); 58 } 59 Solve(); 60 return 0; 61 } View Code?
轉載于:https://www.cnblogs.com/ADAN1024225605/p/4087902.html
總結