Solved | Pro.ID | Title | Ratio(Accepted / Submitted) |
1001 | A + B = C | 10.48%(301/2872) | |
1002 | Bracket Sequences on Tree | 11.27%(16/142) | |
1003 | Cuber Occurrence | 6.67%(1/15) | |
1004 | Data Structure Problem | 23.08%(3/13) | |
1005 | Equation | 0.00%(0/63) | |
1006 | Final Exam 推公式,田忌赛马 | 5.06%(297/5872) | |
1007 | Getting Your Money Back | 12.42%(20/161) | |
1008 | Halt Hater | 14.77%(61/413) | |
1009 | Intersection of Prisms | 0.00%(0/2) | |
1010 | Just Repeat 博弈,贪心 | 15.04%(128/851) | |
1011 | Kejin Player 期望DP | 21.20%(544/2566) |
1001 A + B = C
题意:
给定a,b,c($a, b, c le 10 ^{100000}$),求一组x, y, z满足$a imes 10^x + b imes 10^y = c imes 10^z$ 。
思路:
先把每个数末尾的0去掉,然后可以发现满足如下等式之一$$ a + b = c imes 10 ^k $$ $$ a imes 10 ^k + b = c $$ $$ a + b imes 10 ^ k = c$$就行了。
由于是大数,可以利用哈希,计算等式中的k,可以移项,乘逆元,预处理mod意义下指数。
然后我用到双哈希保险
// #pragma GCC optimize(2) // #pragma GCC optimize(3) // #pragma GCC optimize(4) #include <algorithm> #include <iterator> #include <iostream> #include <cstring> #include <cstdlib> #include <iomanip> #include <bitset> #include <cctype> #include <cstdio> #include <string> #include <vector> #include <stack> #include <cmath> #include <queue> #include <list> #include <map> #include <set> #include <cassert> #include <unordered_map> // #include<bits/extc++.h> // using namespace __gnu_pbds; using namespace std; #define pb push_back #define fi first #define se second #define debug(x) cerr<<#x << " := " << x << endl; #define bug cerr<<"-----------------------"<<endl; #define FOR(a, b, c) for(int a = b; a <= c; ++ a) typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int inf = 0x3f3f3f3f; const ll inff = 0x3f3f3f3f3f3f3f3f; const int mod = 998244353; template<typename T> inline T read(T&x){ x=0;int f=0;char ch=getchar(); while (ch<'0'||ch>'9') f|=(ch=='-'),ch=getchar(); while (ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar(); return x=f?-x:x; } /**********showtime************/ const int maxn = 1e5+9; const int N = 1e5+9; char a[maxn],b[maxn],c[maxn]; char d[maxn]; int mod1 = 998244353, mod2 = 1e9+7; int ten1[N], ten2[N]; unordered_map<int,int>mp1,mp2; void init(){ ten1[0] = ten2[0] = 1; mp1[1] = mp2[1] = 0; for(int i=1; i<N; i++) { ten1[i] = 1ll*ten1[i-1] * 10 % mod1; ten2[i] = 1ll*ten2[i-1] * 10 % mod2; mp1[ten1[i]] = i; mp2[ten2[i]] = i; } } ll ksm(ll a, ll b, ll mod){ ll res = 1; while(b > 0) { if(b & 1) res = res * a % mod; a = a * a % mod; b = b >> 1; } return res; } int main(){ init(); // debug("ok"); int T; scanf("%d", &T); while(T--) { scanf("%s%s%s", a, b, c); int alen = strlen(a), blen = strlen(b), clen = strlen(c); int cnta = 0, cntb = 0, cntc = 0; while(a[alen-1] == '0') alen--, cnta ++; while(b[blen-1] == '0') blen--, cntb ++; while(c[clen-1] == '0') clen--, cntc ++; int kk = max(cnta, max(cntb, cntc)); a[alen] = '