Codeforces Round #700 (Div. 2)
目录
A. Yet Another String Game
贪心。
将所有奇数位置的字符变为 \(a\) (若已经是 \(a\) 则变为 \(b\))。
将所有偶数位置的字符变为 \(z\) (若已经是 \(z\) 则变为 \(y\))。
/**
* Codeforces Round #700 (Div. 2)
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 1005;
void solve()
{
string s;
cin >> s;
for (int i = 0; i < s.size(); ++i) {
if (i%2 == 0) s[i] = s[i]=='a'?'b':'a';
else s[i] = s[i] == 'z'?'y':'z';
}
cout << s << endl;
}
int main()
{
// ios::sync_with_stdio(0); cin.tie(0);
int t = 1;
scanf("%d", &t);
while (t--) {
solve();
}
return 0;
}
B. The Great Hero
贪心。
战胜第 \(i\) 个怪物英雄将受到 \(a_i\cdot \lceil\frac{b_i}{A}\rceil\) 点伤害,战胜所有怪物所受伤害小于 \(B+max(a_i)\) 则输出 \(YES\) 。
/**
* Codeforces Round #700 (Div. 2)
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 1005;
int A, B, n;
struct node {
int a, b;
bool operator < (const node &t) const
{
return 1LL*a*((b+A-1)/A) < 1LL*t.a*((t.b+A-1)/A);
}
};
void solve()
{
scanf("%d%d%d", &A, &B, &n);
vector<node> v(n);
for (auto &e : v) scanf("%d", &e.a);
for (auto &e : v) scanf("%d", &e.b);
//sort(v.begin(), v.end());
LL res = B; int p = 0;
for (auto &e : v) {
LL t = 1LL*e.a*((e.b+A-1)/A);
res -= t;
p = max(p, e.a);
}
if (res+p>0)puts("YES");
else puts("NO");
}
int main()
{
// ios::sync_with_stdio(0); cin.tie(0);
int t = 1;
scanf("%d", &t);
while (t--) {
solve();
}
return 0;
}
C. Searching Local Minimum
Codeforces Round #700 (Div. 2) C(三分)
D. Painting the Array
Codeforces Round #700 (Div. 2) D(贪心)
E. Continuous City
利用二进制进行构造, \(22\) 个城市即可构造出 \(1e6\) 条路径( \(2^{20}>1e6\) ),因此没有 \(NO\) 的情况。
这个不是很会解释。。
/**
* Codeforces Round #700 (Div. 2)
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 1e5+5;
int dis[32][32];
void solve()
{
int L, R;
scanf("%d%d", &L, &R);
puts("YES");
int n = 22, m = 0;
for (int i = 1; i < n; ++i) {
int t = L;
if (i >= 2) t = 1 << i-2;
//cout << i << ' ' << t << '#';
for (int j = i+1; j < n; ++j) {
dis[i][j] = t;
}
}
dis[1][n] = L;
int a = 2, b = R-L, tmp = 1;
while (b) {
if (b&1) dis[a][n] += tmp, tmp += 1<<a-2;
++a;
b >>= 1;
}
for (int i = 1; i <= n; ++i) {
for (int j = i+1; j <= n; ++j) {
m += dis[i][j]!=0;
}
}
printf("%d %d\n", n, m);
for (int i = 1; i <= n; ++i) {
for (int j = 1; j < i; ++j) {
if (dis[j][i]) {
printf("%d %d %d\n", j, i, dis[j][i]);
}
}
}
}
int main()
{
// ios::sync_with_stdio(0); cin.tie(0);
int t = 1;
// scanf("%d", &t);
while (t--) {
solve();
}
return 0;
}