這個年份恐怕須要+2node
#include <bits/stdc++.h> #define fi first #define se second #define pii pair<int,int> #define mp make_pair #define pb push_back #define space putchar(' ') #define enter putchar('\n') #define MAXN 80005 #define eps 1e-10 //#define ivorysi using namespace std; typedef long long int64; typedef double db; template<class T> void read(T &res) { res = 0;T f = 1;char c = getchar(); while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar(); } while(c >= '0' && c <= '9') { res = res * 10 + c - '0'; c = getchar(); } res *= f; } template<class T> void out(T x) { if(x < 0) {x = -x;putchar('-');} if(x >= 10) { out(x / 10); } putchar('0' + x % 10); } int num[10]; void Solve() { for(int i = 1 ; i <= 4 ; ++i) read(num[i]); sort(num + 1,num + 5); if(num[1] == 1 && num[2] == 4 && num[3] == 7 && num[4] == 9) {puts("YES");} else puts("NO"); } int main() { #ifdef ivorysi freopen("f1.in","r",stdin); #endif Solve(); }
……c++
#include <bits/stdc++.h> #define fi first #define se second #define pii pair<int,int> #define mp make_pair #define pb push_back #define space putchar(' ') #define enter putchar('\n') #define MAXN 80005 #define eps 1e-10 //#define ivorysi using namespace std; typedef long long int64; typedef double db; template<class T> void read(T &res) { res = 0;T f = 1;char c = getchar(); while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar(); } while(c >= '0' && c <= '9') { res = res * 10 + c - '0'; c = getchar(); } res *= f; } template<class T> void out(T x) { if(x < 0) {x = -x;putchar('-');} if(x >= 10) { out(x / 10); } putchar('0' + x % 10); } string s; string tar = "keyence"; void Solve() { cin >> s; int p = 0; while(s[p] == tar[p]) ++p; int q = 0; while(s[s.length() - 1 - q] == tar[tar.length() - 1 - q]) ++q; if(p + q >= tar.length()) puts("YES"); else puts("NO"); } int main() { #ifdef ivorysi freopen("f1.in","r",stdin); #endif Solve(); }
就是先用一遍A的總和恢復出B,若是不足就是-1,而後貪心每次恢復最少能夠回到原來的大小數據結構
#include <bits/stdc++.h> #define fi first #define se second #define pii pair<int,int> #define mp make_pair #define pb push_back #define space putchar(' ') #define enter putchar('\n') #define MAXN 100005 #define eps 1e-10 //#define ivorysi using namespace std; typedef long long int64; typedef double db; template<class T> void read(T &res) { res = 0;T f = 1;char c = getchar(); while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar(); } while(c >= '0' && c <= '9') { res = res * 10 + c - '0'; c = getchar(); } res *= f; } template<class T> void out(T x) { if(x < 0) {x = -x;putchar('-');} if(x >= 10) { out(x / 10); } putchar('0' + x % 10); } int N; int64 A[MAXN],B[MAXN],all,C[MAXN]; multiset<int64> S; void Solve() { read(N); for(int i = 1 ; i <= N ; ++i) { read(A[i]);all += A[i]; } for(int i = 1 ; i <= N ; ++i) { read(B[i]);all -= B[i]; if(A[i] - B[i] >= 0) S.insert(A[i] - B[i]); } if(all < 0) {puts("-1");return;} int cnt = 0; while(!S.empty()) { int64 p = *S.begin(); S.erase(S.begin()); if(all >= p) {all -= p;++cnt;} else break; } out(N - cnt);enter; } int main() { #ifdef ivorysi freopen("f1.in","r",stdin); #endif Solve(); }
感受這題so interesting 啊,還能夠往高維拓展
從大到小往裏面塞數,記錄一下每次能用的行和列,若是這個數必須在某一行或某一列,兩個都固定就乘上1,一個固定,好比行固定,就乘上能用的列數
若是這個數位置沒被固定,就是乘上當前能用的行列數的乘積,減去比它大的數
爲何呢。。由於一個數能填的位置,要麼和前面比它大的數都沒有交集,要麼前面比它大的數能填的集合是它的一個真子集ui
#include <bits/stdc++.h> #define fi first #define se second #define pii pair<int,int> #define mp make_pair #define pb push_back #define space putchar(' ') #define enter putchar('\n') #define MAXN 1005 #define eps 1e-10 //#define ivorysi using namespace std; typedef long long int64; typedef double db; template<class T> void read(T &res) { res = 0;T f = 1;char c = getchar(); while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar(); } while(c >= '0' && c <= '9') { res = res * 10 + c - '0'; c = getchar(); } res *= f; } template<class T> void out(T x) { if(x < 0) {x = -x;putchar('-');} if(x >= 10) { out(x / 10); } putchar('0' + x % 10); } const int MOD = 1000000007; int N,M; bool col[MAXN * MAXN],row[MAXN * MAXN]; int inc(int a,int b) { return a + b >= MOD ? a + b - MOD : a + b; } int mul(int a,int b) { return 1LL * a * b % MOD; } void Solve() { read(N);read(M); int a; for(int i = 1 ; i <= N ; ++i) { read(a); if(row[a]) {puts("0");return;} row[a] = 1; } for(int i = 1 ; i <= M ; ++i) { read(a); if(col[a]) {puts("0");return;} col[a] = 1; } int ans = 1; int c = 0,r = 0; for(int i = N * M ; i >= 1 ; --i) { int tc = c,tr = r; if(col[i]) {tc = 1;++c;} if(row[i]) {tr = 1;++r;} if(col[i] || row[i]) ans = mul(ans,tc * tr); else ans = mul(ans,tc * tr - (N * M - i)); } out(ans);enter; } int main() { #ifdef ivorysi freopen("f1.in","r",stdin); #endif Solve(); }
外國人真是瞧不起中國人的數據結構水平
隨手寫了個線段樹就過了
就是拆式子,分\(-i * D + A_i\)和\(i * D + A_i\)
而後跑prim,兩個線段樹取最小的就行spa
#include <bits/stdc++.h> #define fi first #define se second #define pii pair<int,int> #define mp make_pair #define pb push_back #define space putchar(' ') #define enter putchar('\n') #define MAXN 200005 #define eps 1e-10 //#define ivorysi using namespace std; typedef long long int64; typedef double db; template<class T> void read(T &res) { res = 0;T f = 1;char c = getchar(); while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar(); } while(c >= '0' && c <= '9') { res = res * 10 + c - '0'; c = getchar(); } res *= f; } template<class T> void out(T x) { if(x < 0) {x = -x;putchar('-');} if(x >= 10) { out(x / 10); } putchar('0' + x % 10); } int N;int64 D; int64 A[MAXN]; struct seg_tr { struct node { int L,R; int64 cov; pair<int64,int> val[2]; }tr[MAXN * 4]; void update(int u) { tr[u].val[1] = mp(1e16,0); if(tr[u].L != tr[u].R) { tr[u].val[0] = min(tr[u << 1].val[0],tr[u << 1 | 1].val[0]); tr[u].val[1] = min(tr[u << 1].val[1],tr[u << 1 | 1].val[1]); } tr[u].val[1] = min(tr[u].val[1],mp(tr[u].cov + tr[u].val[0].fi,tr[u].val[0].se)); } void build(int u,int l,int r,int on) { tr[u].L = l;tr[u].R = r;tr[u].cov = 1e16; if(l == r) { tr[u].val[0] = mp(A[l] + on * l * D,l); update(u); return; } int mid = (l + r) >> 1; build(u << 1,l,mid,on);build(u << 1 | 1,mid + 1,r,on); update(u); } void Change(int u,int l,int r,int64 v) { if(l > r) return; if(tr[u].L == l && tr[u].R == r) { tr[u].cov = min(tr[u].cov,v); update(u); return; } int mid = (tr[u].L + tr[u].R) >> 1; if(r <= mid) Change(u << 1,l,r,v); else if(l > mid) Change(u << 1 | 1,l,r,v); else {Change(u << 1,l,mid,v);Change(u << 1 | 1,mid + 1,r,v);} update(u); } void Change_pos(int u,int p) { if(tr[u].L == tr[u].R) { tr[u].val[0] = mp(1e16,tr[u].L); update(u);return; } int mid = (tr[u].L + tr[u].R) >> 1; if(p <= mid) Change_pos(u << 1,p); else Change_pos(u << 1 | 1,p); update(u); } }s[2]; void Solve() { read(N);read(D); for(int i = 1 ; i <= N ; ++i) read(A[i]); s[0].build(1,1,N,1); s[1].build(1,1,N,-1); s[0].Change_pos(1,1);s[1].Change_pos(1,1); s[0].Change(1,2,N,A[1] - D); int cnt = N - 1; int64 ans = 0; while(cnt--) { pair<int64,int> t[2]; t[0] = s[0].tr[1].val[1],t[1] = s[1].tr[1].val[1]; if(t[0] > t[1]) swap(t[0],t[1]); ans += t[0].fi; int u = t[0].se; s[0].Change_pos(1,u);s[1].Change_pos(1,u); s[1].Change(1,1,u - 1,1LL * u * D + A[u]); s[0].Change(1,u + 1,N,-1LL * u * D + A[u]); } out(ans);enter; } int main() { #ifdef ivorysi freopen("f1.in","r",stdin); #endif Solve(); }
怎麼又是計數轉指望……輸了……水平不行,從前碰見指望只會轉計數。。。直到atc用一堆計數轉指望把我吊着打rest
就是考慮一個左下角爲\((i,j)\)的方形,當這個點做爲左下角後,每切一刀都會被統計一次,爲了方便咱們姑且只討論\(i > 0\)且\(j > 0\)的狀況code
這個矩形第一次存在的機率是
\(\frac{\binom{K}{2}}{\binom{N}{2}}\)
就是考慮選\(i,j\)(無序)咱們須要它是\(\binom{N}{2}\)中\(\binom{K}{2}\)對中的一個
以後被再次算的機率是,就是,我又拿了一個,左下角爲\(i,j\)的就又被算了一次
\(\frac{\binom{K}{3}}{\binom{N}{3}}\cdot \frac{1}{3}\)我須要最後一個選的點在最後,這樣的機率有\(\frac{1}{3}\)
這樣的點得集合有\(N - 2\)種,因此最後的指望是
\(\frac{\binom{K}{2}}{\binom{N}{2}} + \frac{\binom{K}{3}}{\binom{N}{3}} \cdot \frac{1}{3} \cdot (N - 2)\)
對於邊上的點和角上的一個點也是同理的ci
#include <bits/stdc++.h> #define fi first #define se second #define pii pair<int,int> #define mp make_pair #define pb push_back #define space putchar(' ') #define enter putchar('\n') #define MAXN 20000005 #define eps 1e-10 //#define ivorysi using namespace std; typedef long long int64; typedef double db; template<class T> void read(T &res) { res = 0;T f = 1;char c = getchar(); while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar(); } while(c >= '0' && c <= '9') { res = res * 10 + c - '0'; c = getchar(); } res *= f; } template<class T> void out(T x) { if(x < 0) {x = -x;putchar('-');} if(x >= 10) { out(x / 10); } putchar('0' + x % 10); } const int MOD = 1000000007; int H,W,K,N; int C[2][4],inv[4]; int inc(int a,int b) { return a + b >= MOD ? a + b - MOD : a + b; } int mul(int a,int b) { return 1LL * a * b % MOD; } void update(int &x,int y) { x = inc(x,y); } int fpow(int x,int c) { int res = 1,t = x; while(c) { if(c & 1) res = mul(res,t); t = mul(t,t); c >>= 1; } return res; } void Solve() { read(H);read(W);read(K); N = H + W; inv[1] = 1;inv[2] = (MOD + 1) / 2;inv[3] = (MOD + 1) / 3; C[0][0] = C[1][0] = 1; for(int i = 1 ; i <= 3 ; ++i) { C[0][i] = mul(mul(C[0][i - 1],inv[i]),K - i + 1); C[1][i] = mul(mul(C[1][i - 1],inv[i]),N - i + 1); } int ans = K; int t1 = mul(K,fpow(N,MOD - 2)),t2 = mul(C[0][2],fpow(C[1][2],MOD - 2)),t3 = mul(C[0][3],fpow(C[1][3],MOD - 2)); int s = inc(t1,mul(mul(t2,inv[2]),N - 1)); update(ans,mul(s,H + W)); s = inc(t2,mul(mul(t3,inv[3]),N - 2)); update(ans,mul(s,1LL * H * W % MOD)); for(int i = N ; i >= N - K + 1; --i) { ans = mul(ans,i); } out(ans);enter; } int main() { #ifdef ivorysi freopen("f1.in","r",stdin); #endif Solve(); }