https://ac.nowcoder.com/acm/contest/5666#question
A | B-Suffix Array |
B | Infinite Tree |
C | Domino |
D | Quadratic Form |
E | Counting Spanning Trees |
F | Infinite String Comparision |
首先:明確一件事情,就是只能自己翻譯
翻譯:對於一個字符串X,Bobo定義x可以重復無窮次,然后去比較字典序的大小。與模板題目不同的地方就在於這個字符串x是可以不斷進行累加的
思考:因為要比較字典序的大小,x又可以無限累加,所以只需要找到其最小公倍數就行了,然后累加比較一下字典序就好了
但是,想想可以亂搞,先進行比較一下,然后直接兩倍判斷一下就行!!!真好!!!
經驗:剛就開始的時候隊友跟我說是KMP,直接把我給整傻了20分鍾,我的我的,聽從隊友意見的時候應該先看懂一下題目先
代碼一:神仙代碼,直接就是a+b和b+a進行比較,我人都看傻了,過程還是群友wsx推導出來的,這里特別致謝!!!
A和B在min(lena,lenb)程度下相等時,也就是公共長度下的A和B是相等的
這時候假設A長度更長,B后面+A就相當於是B后面+了B的公共部分,A還是與B進行比較
#include <iostream> #include <cstring> #include <cstdio> #include <cstdlib> #include <algorithm> #include <vector> #include <set> #include <cmath> #define ll long long #define inf 0x3f3f3f3f using namespace std; const int N = 2e6 + 10 ; string a,b ; int main() { while(cin >> a >> b ) { string A = a + b ; string B = b + a ; if(A > B ) cout << ">" << endl; else if(A == B ) cout << "=" << endl; else cout << "<" << endl; } return 0 ; }
思維二:使用gcd求最大公倍數,然后累加數組成新的數組后比較字典序的代碼,但是,這個思維應該是有問題的,因為這個數據是1e6 ; 所以會超長度,不適用
gcd和最小公倍數模板
ll get_gcd(ll a, ll b) { return b == 0 ? a : get_gcd(b , a % b); } ll Least_common_multiple(ll a , ll b ) {
return a * b / get_gcd(a,b); }
代碼三:普通做法,直接先進行比較,然后兩倍長度,繼續比較就夠了
#include <iostream> #include <cstring> #include <vector> #include <cstdio> #include <cstdlib> #include <algorithm> #include <set> #include <cmath> #define ll long long #define inf 0x3f3f3f3f using namespace std; const int N = 2e6 + 10 ; string a , b ; int main() { string a, b; while (cin >> a >> b) { int len_a = a.length(); int len_b = b.length(); if (len_a > len_b) { int t = 0 ; for (t = 0; t < len_a * 2; ++t) { char sum_a = a[t % len_a]; char sum_b = b[t % len_b]; if (sum_a < sum_b) { cout << "<" << endl; break; } else if(sum_a > sum_b) { cout << ">" << endl; break; } } if (t == 2 * len_a) cout << "=" << endl; } else { int t = 0; for (t = 0; t < len_b * 2; t ++ ) { char sum_a = a[t % len_a]; char sum_b = b[t % len_b]; if (sum_a < sum_b) { cout << "<" << endl; break; } else if (sum_a > sum_b) { cout << ">" << endl; break; } } if (t == 2 * len_b) cout << "=" << endl; } } return 0; }
G | BaXianGuoHai, GeXianShenTong |
H | Minimum-cost Flow |
I | 1 or 2 |
J | Easy Integration |