标签:tps XML www 模拟 ring https review 输出 过程
冲鸭,去刷题:https://ac.nowcoder.com/acm/contest/625/C
第一行输入数据组数。T (T≤14)T (T≤14)
接下来T行,每行输入两串只含1∼91∼9的数字,表示两根管子里的小球的数字。每根管子内至少含1个小球,且数量不超过40个。
对每一组数据,输出一行Case #x: A,其中x是数据组数编号(从1开始),A是小六能组成的最大的数。
解题思路:
一:直接暴力模拟,每次取值都要同时从四个端点枚举(直到能判断那个端点最优),取最优端点的值最优。
二:其实上面的模拟过程抽象一下不就是把两个字符串取反后获得四个字符串,然后取字典序最大的那个吗......
AC code:
1 #include <bits/stdc++.h> 2 #define INF 0x3f3f3f3f 3 #define LL long long 4 #define inc(i, j, k) for(int i = j; i <= k; i++) 5 #define rep(i, j, k) for(int i = j; i < k; i++) 6 #define mem(i, j) memset(i, j, sizeof(i)) 7 #define gcd(i, j) __gcd(i, j) 8 using namespace std; 9 const int MAXN = 2e5+10; 10 11 string str, tp, a, b; 12 string ans, res; 13 14 int main() 15 { 16 int T_case; 17 scanf("%d", &T_case); 18 inc(k, 1, T_case){ 19 res = ""; 20 cin >> str >> tp; 21 int L = 0, R = str.size()-1, l = 0, r = tp.size()-1; 22 while(L <= R || l <= r){ 23 ans = ""; 24 a = str; 25 b = tp; 26 reverse(a.begin(), a.end()); 27 reverse(b.begin(), b.end()); 28 29 // cout << L << " " << R << " " <<str << endl; 30 // cout << l << " " << r << " " << tp << endl; 31 // cout << "res: " << res << endl << endl; 32 33 ans = max(ans, max(max(str, a), max(tp, b))); 34 // cout << ans << endl; 35 if(ans == str){ 36 res+=str[L++]; 37 // cout << "1: " << L-1 << " " << res << endl; 38 if(L > R) str = ""; 39 else str = str.substr(L, (R-L+1)); 40 } 41 else if(ans == tp){ 42 res+=tp[l++]; 43 // cout << "2: " << l-1 << " " << res << endl; 44 if(l > r) tp = ""; 45 else tp = tp.substr(l, (r-l+1)); 46 } 47 else if(ans == a){ 48 res+=str[R--]; 49 // cout << "3: " << R+1 << " " << res << endl; 50 if(L > R) str = ""; 51 else str = str.substr(L, (R-L+1)); 52 } 53 else if(ans == b) 54 { 55 res+=tp[r--]; 56 // cout << "4: " << r+1 << " " << res << endl; 57 if(l > r) tp = ""; 58 else tp = tp.substr(l, (r-l+1)); 59 } 60 L = 0;R = str.size()-1;l = 0; r = tp.size()-1; 61 } 62 cout << "Case #" << k << ": " << res << endl; 63 } 64 return 0; 65 }
C 六学家的困惑 【YY】 (2019年华南理工大学程序设计竞赛(春季赛))
标签:tps XML www 模拟 ring https review 输出 过程
原文地址:https://www.cnblogs.com/ymzjj/p/10712554.html