A
#include <bits/stdc++.h>
#define all(n) (n).begin(), (n).end()
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define sqr(n) (n)*(n)
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define IOS ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef double db;
template<class T1, class T2> bool umin(T1& a, T2 b) { return a > b ? (a = b, true) : false; }
template<class T1, class T2> bool umax(T1& a, T2 b) { return a < b ? (a = b, true) : false; }
template<class T> void clear(T& a) { T().swap(a); }
const int N = 1e5 + 5;
int n, m, _, k;
int main() {
IOS;
for (cin >> _; _; --_) {
cin >> n >> m;
if (n <= 2) cout << 1 << '
';
else cout << (n - 3 + m) / m + 1 << '
';
}
return 0;
}
B
只要有
A B
B C
就可以
#include <bits/stdc++.h>
#define all(n) (n).begin(), (n).end()
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define sqr(n) (n)*(n)
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define IOS ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef double db;
template<class T1, class T2> bool umin(T1& a, T2 b) { return a > b ? (a = b, true) : false; }
template<class T1, class T2> bool umax(T1& a, T2 b) { return a < b ? (a = b, true) : false; }
template<class T> void clear(T& a) { T().swap(a); }
const int N = 1e5 + 5;
int n, m, _, k;
int main() {
IOS;
for (cin >> _; _; --_) {
cin >> n >> m;
bool f = 0;
rep (i, 1, n) {
int a, b, c, d; cin >> a >> b >> c >> d;
if (b == c) f = 1;
}
if (f && m % 2 == 0) cout << "YES
";
else cout << "NO
";
}
return 0;
}
C
设 n次 操作中, +1操作有 x次, 则其值为 (1 + x)(n - x)
是个一元二次函数, 最大值怎么取就不用说了吧
#include <bits/stdc++.h>
#define all(n) (n).begin(), (n).end()
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define sqr(n) (n)*(n)
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define IOS ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef double db;
template<class T1, class T2> bool umin(T1& a, T2 b) { return a > b ? (a = b, true) : false; }
template<class T1, class T2> bool umax(T1& a, T2 b) { return a < b ? (a = b, true) : false; }
template<class T> void clear(T& a) { T().swap(a); }
const int N = 1e5 + 5;
int n, m, _, k;
int main() {
IOS;
VI ans(1, 1);
for (int i = 2; ; ++i) {
ll cur = i * (i - 1);
ans.pb(cur); ans.pb(cur + i);
if (cur + i >= 1e9) break;
}
for (cin >> _; _; --_) {
cin >> n;
cout << lower_bound(all(ans), n) - ans.begin() << '
';
}
return 0;
}
D
前缀和的应用,
对于每个位置的前缀和 sum[i] = x,
0~i-1的前缀和中共出现了 y 次 x, 那么以 i 为右端点区间和为 0 的有 y 段
当出现 0 段 你就在 i - 1 插入无限大, sum[i] = a[i], sum[i - 1] = 0即可
#include <bits/stdc++.h>
#define all(n) (n).begin(), (n).end()
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define sqr(n) (n)*(n)
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define IOS ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef double db;
template<class T1, class T2> bool umin(T1& a, T2 b) { return a > b ? (a = b, true) : false; }
template<class T1, class T2> bool umax(T1& a, T2 b) { return a < b ? (a = b, true) : false; }
template<class T> void clear(T& a) { T().swap(a); }
const int N = 2e5 + 5;
int n, m, _, k;
ll a[N], s[N];
int main() {
IOS; cin >> n;
set<ll> st;
rep (i, 1, n) {
cin >> a[i];
s[i] = s[i - 1] + a[i];
if (s[i] == 0 || st.count(s[i])) ++m, clear(st), s[i] = a[i];
st.insert(s[i]);
}
cout << m << '
';
return 0;
}
E
赢最多不用说吧?
赢最少, 无非是 拳头被拳头和包吃了, 剪刀被剪刀和石头吃了, 包被拳头和包吃了
抵消完后, 要么你剩下拳头/剪刀/包, 对手剩下剪刀/包/拳头, 这就是你最少赢的
#include <bits/stdc++.h>
#define all(n) (n).begin(), (n).end()
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define sqr(n) (n)*(n)
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define IOS ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef double db;
template<class T1, class T2> bool umin(T1& a, T2 b) { return a > b ? (a = b, true) : false; }
template<class T1, class T2> bool umax(T1& a, T2 b) { return a < b ? (a = b, true) : false; }
template<class T> void clear(T& a) { T().swap(a); }
const int N = 2e5 + 5;
int n, m, _, k;
int main() {
IOS; cin >> n;
ll a1, a2, a3, b1, b2, b3; cin >> a1 >> a2 >> a3 >> b1 >> b2 >> b3;
ll ans1 = min(a1, b2) + min(a2, b3) + min(a3, b1);
ll ans2 = 2e9;
if (a2 - b1 - b2 > 0) umin(ans2, a2 - b1 - b2);
if (a1 - b1 - b3 > 0) umin(ans2, a1 - b1 - b3);
if (a3 - b3 - b2 > 0) umin(ans2, a3 - b3 - b2);
cout << (ans2 == 2e9 ? 0 : ans2) << ' ' << ans1 << '
';
return 0;
}
F
模拟....把字符串标号给一下,看代码就懂了
1~~a
2~~?
3~~ab
4~~a?
5~~?b
6~~??
7~~abc
8~~ab?
9~~a?c
10~~?bc
11~~a??
12~~?b?
13~~??c
14~~???
#include <bits/stdc++.h>
#define all(n) (n).begin(), (n).end()
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define sqr(n) (n)*(n)
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define IOS ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef double db;
template<class T1, class T2> bool umin(T1& a, T2 b) { return a > b ? (a = b, true) : false; }
template<class T1, class T2> bool umax(T1& a, T2 b) { return a < b ? (a = b, true) : false; }
template<class T> void clear(T& a) { T().swap(a); }
const int N = 2e5 + 5, mod = 1e9 + 7;
int n, m, _, k;
char s[N];
ll a[20], ans = 0;
int qpow(ll a, ll b) {
ll ans = 1; a %= mod;
for (; b; a = a * a % mod, b >>= 1)
if (b & 1) ans = ans * a % mod;
return ans;
}
int main() {
IOS; cin >> n;
cin >> s + 1;
rep (i, 1, n)
if (s[i] == 'a') ++a[1];
else if (s[i] == 'b') {
a[3] += a[1];
a[5] += a[2];
} else if (s[i] == 'c') {
a[7] += a[3];
a[9] += a[4];
a[10] += a[5];
a[13] += a[6];
} else {
a[14] += a[6];
a[12] += a[5];
a[11] += a[4];
a[8] += a[3];
a[6] += a[2];
a[4] += a[1];
++a[2];
}
if (a[7]) ans = a[7] % mod * qpow(3, a[2]) % mod;
if (a[8]) ans = (ans + a[8] % mod * qpow(3, a[2] - 1) % mod) % mod;
if (a[9]) ans = (ans + a[9] % mod * qpow(3, a[2] - 1) % mod) % mod;
if (a[10]) ans = (ans + a[10] % mod * qpow(3, a[2] - 1) % mod) % mod;
if (a[11]) ans = (ans + a[11] % mod * qpow(3, a[2] - 2) % mod) % mod;
if (a[12]) ans = (ans + a[12] % mod * qpow(3, a[2] - 2) % mod) % mod;
if (a[13]) ans = (ans + a[13] % mod * qpow(3, a[2] - 2) % mod) % mod;
if (a[14]) ans = (ans + a[14] % mod * qpow(3, a[2] - 3) % mod) % mod;
cout << ans;
return 0;
}