A题:会赢吗?
思路
大水题
代码
#include <bits/stdc++.h>
using namespace std;
int main() {
double a, b; cin >> a >> b;
cout << (a >= b ? "NO" : "YES") << endl;
return 0;
}
B题:能做到的吧
思路
题意转化为数位是否为降序的
代码
#include <bits/stdc++.h>
using namespace std;
int main() {
int tt; cin >> tt;
while (tt -- ) {
string s; cin >> s;
bool flag = false;
for (int i = 1; i < s.size(); i ++ ) if (s[i] > s[i - 1]) flag = true;
cout << (flag ? "YES" : "NO") << endl;
}
return 0;
}
C题:会赢的!
思路
首先先把初始情况就是平局的条件单独拎出
x < 0 || y < 0 || (x == 0 && y == 0)
接着我们继续分析,怎么样必赢?
一定是在对角线上的时候
比如我们要到(x,y),那么只要我们上次在(x-1,y-1),那么对手无论怎么移动都会让自己赢
所以对于先手,我们观察能否移至对角线的位置(abs(x-y)=1?)
而对于后手,如果本身就在对角线上了,先手移动后,后手就能一直控制在对角线上(x=y)
其余情况都是平局,因为可以直接往一个方向移动,超出x或者y
代码
#include <bits/stdc++.h>
using namespace std;
int main() {
int tt; cin >> tt;
while (tt -- ) {
int x, y; cin >> x >> y;
if (x < 0 || y < 0 || (x == 0 && y == 0)) {
cout << "PING" << endl;
continue;
}
if (abs(x - y) == 1) cout << "YES" << endl;
else if (x == y) cout << "NO" << endl;
else cout << "PING" << endl;
}
return 0;
}
D题:好好好数
思路
转进制
答案为该进制下每一位的最大
60 = (2020)_3
不过要特判1,这个答案为1
代码
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
int main() {
int tt; cin >> tt;
while (tt -- ) {
LL n, k; cin >> n >> k;
if (k == 1) {
cout << 1 << endl;
continue;
}
LL ans = 0;
while (n) {
ans = max(ans, n % k);
n /= k;
}
cout << ans << endl;
}
return 0;
}
E题:好好好数组
思路
正难则反,倒过来看
如果能被模掉的话,那么就直接归零了,之后都是0
不能模掉的话,会剩余一个数,直到后续被模掉
其实这题就是打表找规律
5 1 1 1 0
4 0 0 0 0
3 3 0 0 0
2 2 2 0 0
1 1 1 1 0
0 0 0 0 0
(倒过来看的)
代码
#include <bits/stdc++.h>
using namespace std;
int main() {
int tt; cin >> tt;
while (tt -- ) {
int n, m; cin >> n >> m;
if (m == 1) cout << n + 1 << endl;
else if (m == 2) cout << n << endl;
else if (m == 3) cout << 1 << endl;
else cout << 0 << endl;
}
return 0;
}
F题: 随机化游戏时间?
思路
思路其实很简单,它每次查询,我们只要找出第k小就行
(样例很明确)
找出第k小该怎么操作呢?可持久化线段树
所以说,这道题其实是一道板子题
代码
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
const LL mod = (LL)1e9 + 7;
const int maxn = 2e5;
int n, m, tot;
int sum[(maxn << 5) + 10], rt[(maxn << 5) + 10], ls[(maxn << 5) + 10], rs[(maxn << 5) + 10];
int a[maxn + 10], ind[maxn + 10], len;
int getid(const int& val) {
return lower_bound(ind + 1, ind + 1 + len, val) - ind;
}
int build(int l, int r) {
int root = ++tot;
if (l == r) return root;
int mid = l + r >> 1;
ls[root] = build(l, mid), rs[root] = build(mid + 1, r);
return root;
}
int update(int k, int l, int r, int root) {
int dir = ++tot;
ls[dir] = ls[root], rs[dir] = rs[root], sum[dir] = sum[root] + 1;
if (l == r) return dir;
int mid = l + r >> 1;
if (k <= mid) ls[dir] = update(k, l, mid, ls[root]);
else rs[dir] = update(k, mid + 1, r, rs[root]);
return dir;
}
int query(int u, int v, int l, int r, int k) {
int mid = l + r >> 1, x = sum[ls[v]] - sum[ls[u]];
if (l == r) return l;
if (k <= x) return query(ls[u], ls[v], l, mid, k);
else return query(rs[u], rs[v], mid + 1, r, k - x);
}
int qpow(LL a, LL b) {
int ans = 1;
a = (a % mod + mod) % mod;
for (; b; b >>= 1) {
if (b & 1) ans = (a * ans) % mod;
a = a * a % mod;
}
return ans;
}
int inv(LL x) {
return qpow(x, mod - 2);
}
int main() {
int tt; cin >> tt;
while (tt -- ) {
cin >> n >> m;
for (int i = 1; i <= n; i ++ ) cin >> a[i];
memcpy(ind, a, sizeof ind);
sort(ind + 1, ind + 1 + n);
len = unique(ind + 1, ind + 1 + n) - ind - 1;
rt[0] = build(1, len);
for (int i = 1; i <= n; i ++ ) rt[i] = update(getid(a[i]), 1, len, rt[i - 1]);
int left = 1, right = n;
for (int i = 1, l, r, v; i <= m; i ++ ) {
cin >> l >> r >> v;
int q;
if (!v) q = ind[query(rt[l - 1], rt[r], 1, len, 1)], right = min(right, q - 1);
else if (v == r - l + 1) q = ind[query(rt[l - 1], rt[r], 1, len, v)], left = max(left, q);
else {
q = ind[query(rt[l - 1], rt[r], 1, len, v)];
left = max(left, q);
q = ind[query(rt[l - 1], rt[r], 1, len, v + 1)];
right = min(right, q - 1);
}
}
if (left == right) cout << 1 << ' ' << left << endl;
else cout << inv(right - left + 1) << endl;
}
return 0;
}