T1 簽到題,兩種情況分別計算然後取個min T2 不會QWQ.... 首先一個很顯然的性質就是當$w >8$或$w < -9$的時候是無解的 否則,我們令$D_1=x$,$D_N = x +W$,這樣其它的數就可以任意取了,有$10^{N - 2}$種方案 然後把$x$的取值乘上 具體見代碼吧 T ...
T1
簽到題,兩種情況分別計算然後取個min
#include<vector> #include<map> #include<cstdio> #define min(x, y) (x < y ? x : y) #define max(x, y) (x < y ? y : x) #define abs(x) (x < 0 ? - x : x) #define Pair pair<int, int> #define MP(x, y) make_pair(x, y) using namespace std; const int MAXN = 1e6 + 10, INF = 1e9 + 10; inline int read() { char c = getchar(); int x = 0, f = 1; while(c < '0' || c > '9'){if(c == '-') f = -1; c = getchar();} while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar(); return x * f; } int N; int a[MAXN]; int x = INF, y = INF, z = INF; int main() { #ifdef WIN32 freopen("a.in", "r", stdin); #endif N = read(); for(int i = 1; i <= N; i++) a[i] = read(); for(int i = 1; i <= N; i++) { int opt = read(); if(opt == 1) x = min(x, a[i]); else if(opt == 2) y = min(y, a[i]); else if(opt == 3) z = min(z, a[i]); } printf("%d", min(x + y, z)); return 0; }
T2
不會QWQ....
首先一個很顯然的性質就是當$w >8$或$w < -9$的時候是無解的
否則,我們令$D_1=x$,$D_N = x +W$,這樣其它的數就可以任意取了,有$10^{N - 2}$種方案
然後把$x$的取值乘上
具體見代碼吧
#include<cstdio> #include<cstring> #include<vector> #include<map> #include<cmath> #include<ext/pb_ds/assoc_container.hpp> #include<ext/pb_ds/hash_policy.hpp> #define LL long long using namespace __gnu_pbds; using namespace std; const LL MAXN = 1e6 + 10, INF = 1e9 + 10, mod = 1e9 + 7; inline LL read() { char c = getchar(); LL x = 0, f = 1; while(c < '0' || c > '9'){if(c == '-') f = -1; c = getchar();} while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar(); return x * f; } LL T, N, W; LL fastpow(LL a, LL p) { LL base = 1; while(p) { if(p & 1) base = (base * a) % mod; p >>= 1; a = (a * a ) % mod; } return base % mod; } main() { #ifdef WIN32 freopen("a.in", "r", stdin); //freopen("b.out", "w", stdout); #endif T = read(); while(T--) { N = read(), W = read(); if(W > 8 || W < -9 ) {printf("0\n"); continue;} printf("%lld\n", (W >= 0 ? (9 - W) * fastpow(10, N - 2) : (10 + W) * fastpow(10, N - 2) ) % mod); } }
T3
考慮到值域很小,首先預處理出每個值的出現次數
然後枚舉所有值,再枚舉一個斷點,根據這個數拆開後的兩個數的出現次數算貢獻
兩個數相同的時候需要特判
存值域可以讓每個數加上下界,也可以直接用cc_hash_table,可以卡過
#include<cstdio> #include<cstring> #include<vector> #include<map> #include<ext/pb_ds/assoc_container.hpp> #include<ext/pb_ds/hash_policy.hpp> #define min(x, y) (x < y ? x : y) #define max(x, y) (x < y ? y : x) #define abs(x) (x < 0 ? - x : x) #define Pair pair<int, int> #define MP(x, y) make_pair(x, y) #define int long long using namespace __gnu_pbds; using namespace std; const int MAXN = 1e6 + 10, INF = 1e9 + 10; inline int read() { char c = getchar(); int x = 0, f = 1; while(c < '0' || c > '9'){if(c == '-') f = -1; c = getchar();} while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar(); return x * f; } int T, N; int a[MAXN]; cc_hash_table<int,int>vis; cc_hash_table<int,bool>happen; main() { #ifdef WIN32 freopen("a.in", "r", stdin); #endif T = read(); while(T--) { N = read(); int mx = -INF, mi = INF; vis.clear(); happen.clear(); for(int i = 1; i <= N; i++) a[i] = read(), mx = max(a[i], mx), mi = min(a[i], mi); for(int i = 1; i <= N; i++) vis[a[i]]++; int ans = 0; for(int i = 1; i <= N; i++) { int limit = 2 * a[i]; if(happen[limit]) continue; for(int j = mi; j <= mx; j++) { if(vis[j] && vis[limit - j]) { if(j == (limit - j)) ans += (vis[j] - 1) * vis[j]; else ans += vis[j] * vis[limit - j]; } } happen[limit] = 1; } printf("%lld\n", ans / 2); } }
T4
沒啥可說的
大力特判,細節巨多
#include<cstdio> #include<cstring> #include<vector> #include<map> #include<cmath> #include<ext/pb_ds/assoc_container.hpp> #include<ext/pb_ds/hash_policy.hpp> #define int long long using namespace __gnu_pbds; using namespace std; const int MAXN = 1e6 + 10, INF = 1e9 + 10; inline int read() { char c = getchar(); int x = 0, f = 1; while(c < '0' || c > '9'){if(c == '-') f = -1; c = getchar();} while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar(); return x * f; } int T, N; char s[MAXN]; int a[MAXN], b[MAXN]; main() { #ifdef WIN32 freopen("a.in", "r", stdin); freopen("b.out", "w", stdout); #endif scanf("%d", &T); while(T--) { scanf("%s", s + 1); scanf("%d", &N); int L = strlen(s + 1); for(int i = 1; i <= L; i++) a[i] = a[i - 1], b[i] = b[i - 1], s[i] == 'a' ? a[i]++ : b[i]++; int ans = 0; if(a[L] > b[L]) { for(int i = 1; i <= L; i++) { if(a[i] > b[i]) ans = ans + N; else if(a[i] == b[i]) ans = ans + N - 1; else { ans = ans + max((int)0, N - 1 - (b[i] - a[i]) / (a[L] - b[L])); } } } else if(a[L] == b[L]) { for(int i = 1; i <= L; i++) { if(a[i] > b[i]) ans = ans + N; else continue; } } else { for(int i = 1; i <= L; i++) { if(a[i] > b[i]) ans = ans + min(N, (a[i] - b[i]) / (b[L] - a[L]) + (bool)((a[i] - b[i]) % (b[L] - a[L]))); else continue; } } printf("%lld\n", ans); } }
剩下的還沒做
等APIO結束再說吧(估計也做不動了)