#include<bits/stdc++.h> usingnamespace std; // 博弈论:Nim // http://newoj.acmclub.cn/problems/2013 constint MOD = 1e9 + 7; int T; int n, m; int a[1000100]; int sum[1000100]; int f[1000100]; intmain() { ios::sync_with_stdio(false); cin.tie(0), cout.tie(0); cin >> T; while (T--) { cin >> n >> m; memset(sum, 0, sizeof(sum)); for (int i = 1; i <= n; i++) { cin >> a[i]; sum[i] = sum[i - 1] ^ a[i]; } for (int i = 1; i <= m; i++) { int l, r; cin >> l >> r; int result = sum[r] ^ sum[l - 1]; //第i次结果 if (result) f[i] = 1; else f[i] = 0; } longlong ans = 0; for (int i = 1; i <= m; i++) { ans = ans << 1; ans += f[i]; ans = ans % MOD; } cout << ans << endl; } return0; }
神殿
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#include<bits/stdc++.h> usingnamespace std; // http://newoj.acmclub.cn/problems/2016 longlong l, r; intmain() { ios::sync_with_stdio(false); cin.tie(0), cout.tie(0); cin >> l >> r; while (l <= r) { if ((l | l + 1) > r) //(l | l + 1)为的是将l的最低一位0尝试改成1 break; l = (l | l + 1); } cout << l << endl; return0; }
#include<bits/stdc++.h> usingnamespace std; // TLE解法。。。 int n, m; int graph[510][510]; int ans[510][510]; int cnt; structnode { int x, y; } point[250010]; intmain() { ios::sync_with_stdio(false); cin.tie(0), cout.tie(0); memset(ans, 0x3f, sizeof(ans)); cin >> n >> m; for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) { cin >> graph[i][j]; if (graph[i][j]) { ++cnt; point[cnt].x = i; point[cnt].y = j; } } for (int k = 1; k <= cnt; k++) { for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { if (graph[i][j]) ans[i][j] = 0; else ans[i][j] = min(ans[i][j], abs(point[k].x - i) + abs(point[k].y - j)); } } } for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { cout << ans[i][j]; if (j != m) cout << " "; } cout << endl; } return0; }
#include<bits/stdc++.h> usingnamespace std; // 快速幂 #define MOD 20180520 longlongfast_power(longlong a, longlong b, longlong c) { longlong ans = 1; a = a % c; while (b) { if (b % 2) ans = (ans * a) % c; b /= 2; a = (a * a) % c; } return ans; } intmain() { ios::sync_with_stdio(false); cin.tie(0), cout.tie(0); longlong n; cin >> n; cout << fast_power(2, n, MOD); return0; }