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 |