标签:not oss home break amp typedef expr int long
Solved:3
rank:405.................................
B. Harvest of Apples
知道了S(n,m) 可以o(1)的求S(n - 1, m),S(n + 1,m),S(n,m - 1),S(n,m + 1) 天秀莫队
#include <stdio.h> #include <algorithm> #include <iostream> using namespace std; typedef long long ll; const ll mod = 1e9 + 7; int blo = 200; ll ans; ll f[100005]; ll inv[100005]; ll anss[100005]; ll pow_mod(ll x, ll y) { ll res = 1; while(y) { if(y & 1) res = res * x % mod; x = x * x % mod; y >>= 1; } return res; } void prework() { f[0] = 1; inv[0] = 1; for(int i = 1; i <= 100000; i++) f[i] = f[i - 1] * 1LL * i % mod; for(int i = 1; i <= 100000; i++) inv[i] = pow_mod(f[i], mod - 2LL); } struct node { int n, m, id; }E[100005]; bool cmp(node A, node B) { int a = (A.n - 1) / blo; int b = (B.n - 1) / blo; if(a == b) return A.m < B.m; else return a < b; } int main() { ans = 1; prework(); int T; scanf("%d", &T); for(int i = 1; i <= T; i++) { scanf("%d%d", &E[i].n, &E[i].m); E[i].id = i; } sort(E + 1, E + 1 + T, cmp); ll n = 1, m = 0; for(int i = 1; i <= T; i++) { while(n < E[i].n) { ans *= 2LL; ll tmp = f[n] * inv[m] % mod * inv[n - m] % mod; ans = (ans - tmp + mod) % mod; n++; } while(m > E[i].m) { ll tmp = f[n] * inv[m] % mod * inv[n - m] % mod; ans = (ans - tmp + mod) % mod; m--; } while(n > E[i].n) { ll tmp = f[n - 1] * inv[m] % mod * inv[n - 1 - m] % mod; ans += tmp; ans = ans * inv[2] % mod; n--; } while(m < E[i].m) { ll tmp = f[n] * inv[m + 1] % mod * inv[n - m - 1] % mod; ans = (ans + tmp) % mod; m++; } anss[E[i].id] = ans; } for(int i = 1; i <= T; i++) printf("%lld\n", anss[i]); return 0; }
D. Nothing is Impossible
题意出锅 秒变签到题
#include <stdio.h> #include <algorithm> #include <iostream> #include <string.h> using namespace std; typedef long long ll; struct node { int a, b; }E[105]; bool cmp(node A, node B) { return A.b < B.b; } int main() { int T; scanf("%d", &T); while(T--) { int n, m; scanf("%d%d", &n, &m); for(int i = 1; i <= n; i++) scanf("%d%d", &E[i].a, &E[i].b); sort(E + 1, E + 1 + n, cmp); ll tmp = 1; int ans = n; for(int i = 1; i <= n; i++) { if(tmp * (E[i].b + 1LL) <= m) { tmp *= (E[i].b + 1LL); } else { ans = i - 1; break; } } printf("%d\n", ans); } return 0; }
K. Expression in Memories
#include <stdio.h> #include <algorithm> #include <iostream> #include <string.h> using namespace std; char s[505]; int vis[505]; int main() { int T; scanf("%d", &T); while(T--) { memset(vis, 0, sizeof(vis)); scanf("%s", s); int len = strlen(s); bool f = true; for(int i = 0; i < len; i++) { if(s[i] == ‘+‘) { if(i == 0 || i == len - 1) f = false; if(i + 1 < len && s[i + 1] == ‘+‘) f = false; if(i + 1 < len && s[i + 1] == ‘*‘) f = false; } else if(s[i] == ‘*‘) { if(i == 0 || i == len - 1) f = false; if(i + 1 < len && s[i + 1] == ‘+‘) f = false; if(i + 1 < len && s[i + 1] == ‘*‘) f = false; } else if(s[i] - ‘0‘ > 0 && s[i] - ‘0‘ <= 9) vis[i] = 1; else if(s[i] == ‘0‘) { if(i - 1 >= 0 && vis[i - 1] == 1) vis[i] = 1; else { if(i + 1 < len && s[i + 1] - ‘0‘ >= 0 && s[i + 1] - ‘0‘ <= 9) f = false; else if(i + 1 < len && s[i + 1] == ‘?‘) s[i + 1] = ‘+‘; } } else if(s[i] == ‘?‘) { if(i == 0 || i + 1 == len) s[i] = ‘1‘, vis[i] = 1; else if(i - 1 >= 0 && vis[i - 1] == 0) { if(s[i - 1] == ‘0‘) s[i] = ‘+‘; else s[i] = ‘1‘, vis[i] = 1; } else { s[i] = ‘1‘, vis[i] = 1; } } } if(!f) puts("IMPOSSIBLE"); else printf("%s\n", s); } return 0; }
L. Graph Theory Homework
#include <stdio.h> #include <algorithm> #include <iostream> #include <cmath> using namespace std; int q[100005]; int main() { int T; scanf("%d", &T); while(T--) { int n; scanf("%d", &n); for(int i = 1; i <= n; i++) scanf("%d", &q[i]); int ans = sqrt(abs(q[n] - q[1])); printf("%d\n", ans); } return 0; }
标签:not oss home break amp typedef expr int long
原文地址:https://www.cnblogs.com/lwqq3/p/9404574.html