首页 > 其他分享 >A - Swap Digit

A - Swap Digit

时间:2023-01-23 18:33:06浏览次数:38  
标签:Digit AB 互换 long Swap https

A - Swap Digit

https://atcoder.jp/contests/arc154/tasks/arc154_a

 

思路

A 和 B中数字需要互换,

互换的准则是,使得 互换后的 AB 乘积最小, 互换后的 A 和 B 差值尽量大

即: 将对应位置的 数字, 小的数字放在A, 大的数字放在B

 

互换后的AB

A * B mod F

= A mod F * B mod F

 

AB 都是大数,大数取模如下:

https://blog.csdn.net/qq_38192377/article/details/90212284

 

Code

https://atcoder.jp/contests/arc154/submissions/38277636

#include <bits/stdc++.h>
using namespace std;

long long M(string s,long long modu){
    long long ans=0;
    for(int i=0;i<s.size();i++){
        ans*=10;
        ans+=(s[i]-'0');
        ans%=modu;
    }
    return ans;
}

int main(){
    int n;
    string a,b;
    cin>>n>>a>>b;
    for(int i=0;i<n;i++){
        if(a[i]>b[i]){
            swap(a[i],b[i]);
        }
    }
    cout<<(M(a,998244353)*M(b,998244353))%998244353<<endl;
} 

 

标签:Digit,AB,互换,long,Swap,https
From: https://www.cnblogs.com/lightsong/p/17065364.html

相关文章