这场就做出一道题,怎么会有窝这么辣鸡的人呢?
很复杂的公式,打表找的规律,最后是m^0+m^1+...+m^n,题解直接是(m^(n+1)-1)/(m-1),长姿势,原来还能化简……做出来的题不写题解了。
一个棋盘,走棋的姿势要满足(x1-x2)^2+(y1-y2)^2==5,也就是以“日”字走,且只能向右下走。
其中有一些障碍不能经过,注意障碍有可能在终点,求从(1,1)走到(n,m)的路径数。
容斥+组合数 这题的简单版CF559C(对啊,我做过这题,我还是没做出来,wa了十多次,啦啦啦)
over是防止重点的,感觉不会有重点,但是比赛时是实在没辙了=_=#
#include <cstdio> #include <cstring> #include <vector> #include <algorithm> #include <iostream> using namespace std; typedef long long ll; const ll MOD = 110119; const int MAX_P = 2000005; ll powMod(ll a, ll b, ll mod) { ll res = 1; while (b) { if (b & 1) res = res * a % mod; a = a * a % mod; b >>= 1; } return res; } ll fac[MAX_P]; void getFact() { fac[0] = 1; for (int i = 1; i <= 2000000; ++i) fac[i] = fac[i - 1] * i % MOD; } ll Lucas(ll n, ll m, ll p) { ll res = 1; while (n && m) { ll a = n % p; ll b = m % p; if (a < b) return 0; res = res * fac[a] % p * powMod(fac[b] * fac[a - b] % p, p - 2, p) % p; n /= p; m /= p; } return res; } struct Point { ll x, y; Point(ll x, ll y):x(x),y(y){} Point(){} bool operator<(const Point a) const { if (x == a.x) return y < a.y; return x < a.x; } bool operator==(const Point a) const { if (x == a.x && y == a.y) return true; return false; } } p[2005]; ll cal(Point a, Point b) { ll dx = b.x - a.x; ll dy = b.y - a.y; ll r, c; if ((dx*2-dy)%3 || (dy*2-dx)%3) return 0; ll inv = powMod(3, MOD-2, MOD); r = (2 * dx - dy) / 3; c = (2 * dy - dx) / 3; if (r < 0 || c < 0) return 0; if (c == 0 || r == 0) return 1; return Lucas(r+c, r, MOD); } ll ans[2005]; bool over[2005]; int main() { //freopen("in", "r", stdin); ll m, n, r; getFact(); int cas = 0; while (cin >> m >> n >> r) { printf("Case #%d: ", ++cas); Point s(1, 1); for (int i = 0; i < r; ++i) scanf("%lld%lld", &p[i].x, &p[i].y); p[r].x = m, p[r].y = n; sort(p, p + r); if (p[r-1].x == m && p[r-1].y == n) { printf("0\n"); continue; } memset(over, false, sizeof over); for (int i = 1; i < r; ++i) { if (p[i] == p[i-1]) over[i] = true; } for (int i = 0; i <= r; ++i) { if (over[i]) continue; ans[i] = cal(s, p[i]); for (int j = 0; j < i; ++j) { if (over[j]) continue; if (p[j].x < p[i].x && p[j].y < p[i].y) { ans[i] = ((ans[i] - cal(p[j], p[i]) * ans[j] % MOD) % MOD + MOD) % MOD; } } } ans[r] = (ans[r] + MOD) % MOD; printf("%lld\n", ans[r]); } return 0; }
nim博弈变形
有n堆糖,每次拿走一堆的任意个, 或者把一堆分成三堆。
对一堆求SG函数值,然后打表找规律,感觉不难,但是没想明白,后来有一个网友提醒我(额 虽然比赛时这样不太好……),终于开始写,其实一开始我是蒙蔽的,写写的突然清晰了,但是错了一个数……sg[2]应该是2,我竟然随手写成了0,妈蛋T^T
#include <cstdio> #include <cstring> #include <vector> #include <algorithm> #include <iostream> using namespace std; #define PF(x) cout << "debug: " << x << " "; #define EL cout << endl; #define PC(x) puts(x); typedef long long ll; const int N = 1000005; const int MOD = 1e9+7; int a[N]; int sg[N]; int get_sg(int x) { if (x == 0) return 0; if (x == 1) return 1; if (x == 2) return 2; if (sg[x] != -1) return sg[x]; int mex[200000] = {0}; for (int i = 1; i < x; ++i) { for (int j = i; j < x-i; ++j) { int k = x - i - j; if (k <= 0) break; int tmp = get_sg(i) ^ get_sg(j) ^ get_sg(k); mex[tmp] = 1; } } for (int i = 0; i < x; ++i) { mex[get_sg(i)] = 1; } for (int i = 0; ; i++) { if (!mex[i]) return sg[x] = i; } } int main(int argc, char const *argv[]) { // memset(sg, -1, sizeof sg); // for (int i = 0; i < 100; ++i) { // cout << i << " " << get_sg(i) << endl; // } //freopen("in", "r", stdin); int T; scanf("%d", &T); while (T--) { int n; scanf("%d", &n); int ans = 0; for (int i = 0; i < n; ++i) { scanf("%d", a+i); if (a[i] % 8 == 0) a[i]--; else if (a[i] % 8 == 7) a[i]++; ans ^= a[i]; } printf("%s\n", ans ? "First player wins.":"Second player wins."); } return 0; }
怎么会有窝这么弱的人呢?
时间: 2024-12-16 06:18:06