A
/* Huyyt */#include#define mem(a,b) memset(a,b,sizeof(a))#define mkp(a,b) make_pair(a,b)#define pb push_backusing namespace std;typedef long long ll;const long long mod = 1e9 + 7;const int N = 2e5 + 5;int num[1005];int main(){ int n; cin >> n; for(int i=1;i<=n;i++) { cin >> num[i]; } sort(num+1,num+1+n); int now=0; if(n%2) { cout<
B
/* Huyyt */#include#define mem(a,b) memset(a,b,sizeof(a))#define mkp(a,b) make_pair(a,b)#define pb push_backconst int dir[8][2] = { { 0, 1}, { 1, 0}, { 0, -1}, { -1, 0}, { 1, 1}, { 1, -1}, { -1, -1}, { -1, 1}};using namespace std;typedef long long ll;const long long mod = 1e9 + 7;const int N = 2e5 + 5;char f[105][105];int n, m;bool ok(int x, int y){ if (x > n || x < 1) { return false; } if (y > m || y < 1) { return false; } return true;}int main(){ cin >> n >> m; for (int i = 1; i <= n; i++) { scanf("%s", f[i] + 1); } for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { if (f[i][j] == '*') { continue; } if (f[i][j] == '.') { for (int w = 0; w < 8; w++) { int dx = i + dir[w][0]; int dy = j + dir[w][1]; if (ok(dx, dy)) { if (f[dx][dy] == '*') { cout << "NO" << endl; return 0; } } } } else { int now = 0; int cur = f[i][j] - '0'; for (int w = 0; w < 8; w++) { int dx = i + dir[w][0]; int dy = j + dir[w][1]; if (ok(dx, dy)) { if (f[dx][dy] == '*') { now++; } } } if (now != cur) { cout << "NO" << endl; return 0; } } } } cout << "YES" << endl; return 0;}
C
好题。。应该是我做过最难的2C了
给你 p q b 三个1e18的数 问你在b进制下p/q能不能被有限地表现出来
首先把p与q约分 考虑1/q能不能在b进制在被表现出来
因为b进制下每退一位所表示的数就小b倍
所以我们可以把被除数乘上b再除q就是这一位小数的值 即\(\frac{3*4}{5}=2\)
同时被除数变为\(\frac{3}{5}\)\(\%\) \(\frac{1}{4}\)=\(\frac{(3*4)\%5}{5}\)=\(\frac{2}{5}\)
这样进行下去看能不能在某一步被除数分子乘上b是q的倍数
即存在n使得 \(b^{n}\ mod\ q=0\) 但是我们不可能枚举n来检验是否存在
由唯一分解定理可知 \(b^{n}\ mod\ q=0\) 等价于b的因子中存在所有q的质因子
/*Huyyt*/#include#define mem(a,b) memset(a,b,sizeof(a))#define pb push_backusing namespace std;typedef long long ll;typedef unsigned long long ull;const ll LLmaxn = 2e18;const int N = 100005;int n;inline ll readint(){ char c = getchar(); ll ans = 0; while (c < '0' || c > '9') { c = getchar(); } while (c >= '0' && c <= '9') { ans = ans * 10LL + c - '0', c = getchar(); } return ans;}ll gcd(ll a, ll b){ ll t; while (b) { t = b; b = a % b; a = t; } return a;}int main(){ n=readint(); ll p, q, b; for (int i = 1; i <= n; i++) { p=readint(),q=readint(),b=readint(); ll now = gcd(p, q); p /= now, q /= now; if (q == 1) { cout << "Finite" << endl; continue; } p %= q; if (p == 0) { cout << "Finite" << endl; continue; } now = gcd(q, b); while (now != 1) { while (q % now == 0) { q /= now; } now=gcd(q,b); } if (q == 1) { cout << "Finite" << endl; } else { cout << "Infinite" << endl; } }}
D
给你一个f函数(类似于石子合并花费 只是把+变成XOR操作)
直接n2用类似石子合并的思想先把小的区间处理出来dp[i][i + len] = dp[i][i + len - 1] ^ dp[i + 1][i + len]
再汇总dp[i][i + len] = max(max(dp[i][i + len - 1], dp[i + 1][i + len]), dp[i][i + len])
/*Huyyt*/#include#define mem(a,b) memset(a,b,sizeof(a))#define pb push_backusing namespace std;typedef long long ll;typedef unsigned long long ull;const ll LLmaxn = 2e18;const int N = 100005;inline int readint(){ char c = getchar(); int ans = 0; while (c < '0' || c > '9') { c = getchar(); } while (c >= '0' && c <= '9') { ans = ans * 10 + c - '0', c = getchar(); } return ans;}int number[5005];int dp[5005][5005];int main(){ int now = 0; int n; n = readint(); for (int i = 1; i <= n; i++) { number[i] = readint(); } for (int i = 1; i <= n; i++) { dp[i][i] = number[i]; } for (int len = 1; len <= n - 1; len++) { for (int i = 1; i <= n - len; i++) { dp[i][i + len] = dp[i][i + len - 1] ^ dp[i + 1][i + len]; } } for (int len = 1; len <= n - 1; len++) { for (int i = 1; i <= n - len; i++) { dp[i][i + len] = max(max(dp[i][i + len - 1], dp[i + 1][i + len]), dp[i][i + len]); } } int l, r; int q; q = readint(); while (q--) { l = readint(), r = readint(); cout << dp[l][r] << endl; }}