Infinite String Comparision

链接:https://ac.nowcoder.com/acm/contest/5666/F
来源:牛客网

题目描述
For a string x x x, Bobo defines x ∞ = x x x … x^\infty = x x x \dots x=xxx, which is x x x repeats for infinite times, resulting in a string of infinite length.

Bobo has two strings aa and bb. Find out the result comparing a ∞ a^\infty a and b ∞ b^\infty b in lexicographical order.

You can refer the wiki page for further information of Lexicographical Order.

输入描述:
The input consists of several test cases terminated by end-of-file.

The first line of each test case contains a string a a a, and the second line contains a a a string b b b.

  • 1 ≤ ∣ a ∣ , ∣ b ∣ ≤ 1 0 5 1 \leq |a|, |b| \leq 10^5 1a,b105

  • a a a, b b b consists of lower case letters.

  • The total length of input strings does not exceed 2 × 1 0 6 2 \times 10^6 2×106.

输出描述:
For each test case, print “=” (without quotes) if a ∞ = b ∞ a^\infty = b^\infty a=b. Otherwise, print “<” if a ∞ < b ∞ a^\infty < b^\infty a<b, or “>” if a ∞ > b ∞ a^\infty > b^\infty a>b.

示例1

输入
aa
b
zzz
zz
aba
abaa
输出
<
=
>

s 1 = a + b s_1=a+b s1=a+b s 2 = b + a s_2=b+a s2=b+a,则
s 1 ∞ = a b a b a b … s_1^\infty=ababab\dots s1=ababab
s 2 ∞ = b a b a b a … s_2^\infty=bababa\dots s2=bababa
显然 s 1 ∞ s_1^\infty s1 s 2 ∞ s_2^\infty s2都包含子序列 a ∞ a^\infty a b ∞ b^\infty b,且 s 1 s_1 s1 s 2 s_2 s2的字典序大小关系与 s 1 ∞ s_1^\infty s1 s 2 ∞ s_2^\infty s2的字典序大小关系相同。
s 1 ∞ s_1^\infty s1 s 2 ∞ s_2^\infty s2长度相等,则可以把序列看做是数字,字典序大小看做是数字大小的比较。
比较大小应当是各位的数乘上对应位的权值,不妨设 s 1 ∞ s_1^\infty s1 a ∞ a^\infty a对应的权值总和为 s u m 1 sum_1 sum1 b ∞ b^\infty b对应的权值总和为 s u m 2 sum_2 sum2,则 s 1 ∞ s_1^\infty s1 a ∞ a^\infty a对应的权值总和为 s u m 2 sum_2 sum2 b ∞ b^\infty b对应的权值总和为 s u m 1 sum_1 sum1
s 1 ∞ − s 2 ∞ = ( s u m 1 ⋅ a ∞ + s u m 2 ⋅ b ∞ ) − ( s u m 2 ⋅ a ∞ + s u m 1 ⋅ b ∞ ) = ( s u m 1 − s u m 2 ) ⋅ ( a ∞ − b ∞ ) \begin{aligned} s_1^\infty-s_2^\infty &=(sum_1·a^\infty+sum_2·b^\infty)-(sum_2·a^\infty+sum_1·b^\infty)\\ &=(sum_1-sum_2)·(a^\infty-b^\infty) \end{aligned} s1s2=(sum1a+sum2b)(sum2a+sum1b)=(sum1sum2)(ab)
显然 s u m 1 − s u m 2 > 0 sum_1-sum_2>0 sum1sum2>0
因此 a ∞ a^\infty a b ∞ b^\infty b的字典序大小关系与 s 1 ∞ s_1^\infty s1 s 2 ∞ s_2^\infty s2的字典序大小关系相同。
a ∞ a^\infty a b ∞ b^\infty b的字典序大小关系与 s 1 s_1 s1 s 2 s_2 s2的字典序大小关系相同。
因此直接比较 s 1 s_1 s1 s 2 s_2 s2的字典序大小关系即可。复杂度为 O ( n ) O(n) O(n)

#include<bits/stdc++.h>

#define si(a) scanf("%d",&a)
#define sl(a) scanf("%lld",&a)
#define sd(a) scanf("%lf",&a)
#define sc(a) scahf("%c",&a);
#define ss(a) scanf("%s",a)
#define pi(a) printf("%d\n",a)
#define pl(a) printf("%lld\n",a)
#define pc(a) putchar(a)
#define ms(a) memset(a,0,sizeof(a))
#define repi(i, a, b) for(register int i=a;i<=b;++i)
#define repd(i, a, b) for(register int i=a;i>=b;--i)
#define reps(s) for(register int i=head[s];i;i=Next[i])
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define pii pair<int,int>
#define mii unordered_map<int,int>
#define msi unordered_map<string,int>
#define lowbit(x) ((x)&(-(x)))
#define ce(i, r) i==r?'\n':' '
#define pb push_back
#define fi first
#define se second
#define INF 0x3f3f3f3f
#define pr(x) cout<<#x<<": "<<x<<endl
using namespace std;

inline int qr() {
    int f = 0, fu = 1;
    char c = getchar();
    while (c < '0' || c > '9') {
        if (c == '-')fu = -1;
        c = getchar();
    }
    while (c >= '0' && c <= '9') {
        f = (f << 3) + (f << 1) + c - 48;
        c = getchar();
    }
    return f * fu;
}

string a, b;
string s1, s2;

int main() {
    while (cin >> a, cin >> b) {
        s1 = a + b, s2 = b + a;
        if (s1 > s2)puts(">");
        else if (s1 < s2)puts("<");
        else puts("=");
    }
    return 0;
}
infinite linear是CSS3动画属性中的两个参数。其中infinite表示动画将无限循环,即不会停止,会一直重复播放。而linear表示动画的速度是匀速的,即从开始到结束的过程中,动画的速度保持恒定,没有变化。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [【原创】使用纯CSS3制作一个无限循环的动画](https://blog.csdn.net/weixin_30726161/article/details/95972354)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [Linear Algebra【Stephen H. Friedberg】](https://download.csdn.net/download/sigkill/10823777)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [用CSS3制作太阳系行星运动简图](https://blog.csdn.net/qq_41319331/article/details/89555785)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

_sky123_

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值