A - 柠檬可乐
string solve() {
int a, b, k; cin >> a >> b >> k;
return a >= k * b ? "good" : "bad";
}
B - 左右互博
每次将一堆石子分成两堆,必然最后结果会多一个 1 1 1,因此只要看能多几个 1 1 1,即为可以操作的次数
string solve() {
cin >> n;
ll sum = 0;
for (int i = 0; i < n; i ++) cin >> a[i], sum += a[i];
return sum - n & 1 ? "gui" : "sweet";
}
C - 冬眠
暴力模拟
char solve() {
cin >> n >> m >> x >> y;
for (int i = 0; i < n; i ++) cin >> s[i];
cin >> p >> q;
for (int i = 0; i < q; i ++) {
cin >> e[i].aa >> e[i].bb;
e[i].bb --;
}
while (p --) {
for (int i = 0; i < q; i ++) {
if (e[i].aa == 1) {
char c = s[e[i].bb][m - 1];
for (int j = m - 1; j; j --) s[e[i].bb][j] = s[e[i].bb][j - 1];
s[e[i].bb][0] = c;
} else {
char c = s[n - 1][e[i].bb];
for (int j = n - 1; j; j --) s[j][e[i].bb] = s[j - 1][e[i].bb];
s[0][e[i].bb] = c;
}
}
}
return s[-- x][-- y];
}
D - 守恒
重新分配数,由于 g c d × k = s u m , k ≥ n gcd\times k=sum,~k\ge n gcd×k=sum, k≥n,故 g c d ∣ n gcd|n gcd∣n
注意特判 n = 1 n=1 n=1 时
ll solve() {
cin >> n;
ll sum = 0, res = 0;
for (int i = 0; i < n; i ++) cin >> a[i], sum += a[i];
for (int i = 1; i <= sum / n; i ++)
if (sum % i == 0) res ++;
if (n == 1) return 1;
return res;
}
E - 漂亮数组
只许看前缀和相同的区间点,每次找到后 c l e a r clear clear 前面的已经被选择过的
int solve() {
cin >> n >> k;
int idx = 0;
map<int, int> mp;
for (int i = 1; i <= n; i ++) {
cin >> a[i];
a[i] += a[i - 1];
a[i] %= k;
}
set<int> s;
s.insert(0);
int res = 0;
for (int i = 1; i <= n; i ++) {
if (s.count(a[i])) {
res ++;
s.clear();
}
s.insert(a[i]);
}
return res;
}
F - 来点每日一题
G - 数三角形(easy)
前缀和查询底边是否存在,总复杂度 O ( n 3 ) O(n^3) O(n3)
ll solve() {
cin >> n >> m;
for (int i = 0; i < n; i ++) cin >> s[i];
for (int i = 0; i < n; i ++)
for (int j = 0; j < m; j ++)
a[i][j + 1] = a[i][j] + (s[i][j] == '*');
ll res = 0;
for (int i = 0; i < n; i ++)
for (int j = 1; j < m - 1; j ++) {
if (s[i][j] == '.') continue;
for (int k = 1; k <= min(j, min(m - 1 - j, n - 1 - i)); k ++) {
if (s[i + k][j - k] == '*' && s[i + k][j + k] == '*') {
if (a[i + k][j + k + 1] - a[i + k][j - k] >= k * 2 + 1) res ++;
} else break;
}
}
return res;
}