Educational Codeforces Round 122 (Rated for Div. 2) A ~ D
Posted Ja_King_ZH
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Educational Codeforces Round 122 (Rated for Div. 2) A ~ D相关的知识,希望对你有一定的参考价值。
https://codeforces.com/contest/1633/problem/A
题意:通过改变最小次数得到7的倍数,每次只能改变一位。
题解:只需改变各位即可,也就是枚举个位,从0到9,判断能否被7整除。
int main()
int t;
cin >> t;
while (t--)
int x;
string res;
cin >> res;
x = res[0] - '0';
if (res.size() > 2) x = x * 10 + res[1] - '0';
int y = 0;
for (int i = 0; i < res.size();i++)
y += (res[i] - '0') * pow(10, res.size() - 1 - i);
if (y % 7 == 0) cout << y << endl;
else
cout << x;
for (int i = 0; i < 10; i++)
if ((x * 10 + i) % 7 == 0)
cout << i << endl;
break;
return 0;
https://codeforces.com/contest/1633/problem/B
题意:给定一个字符串,由01组成,选择一定长度的字符串,删除该字符串较小的字符,问最多能删除多少个。
题解:结论题。若0和1长度相同,则为长度-1,若不同,则为字符串较小的那个。
const int N = 2e5 + 10;
int a[N], b[N];
int main()
int t;
cin >> t;
while (t--)
string res;
cin >> res;
for (int i = 0; i < res.size(); i++)
if (res[i] == '0') a[i + 1]++;
else b[i + 1]++;
a[i + 1] += a[i];
b[i + 1] += b[i];
int ans = 0;
for (int i = 1; i <= res.size(); i++)
if (a[i] != b[i]) ans = min(a[i], b[i]);
cout << ans << endl;
for (int i = 0; i <= res.size(); i++) a[i] = b[i] = 0;
return 0;
https://codeforces.com/contest/1633/problem/C
题意:给定玩家生命值和攻击值,怪兽的生命值和攻击值。以及可以强化的次数,每次强化可以选择增加w点攻击值或者a点血量值,问能否击败怪兽。
题解:直接枚举所有情况,判断有无击杀怪兽的强化方法。但需要注意爆longlong,因此只能算击杀次数(即多少次可以杀死对方)
#define int long long
signed main()
int t;
cin >> t;
while (t--)
int hc, dc, hm, dm;
cin >> hc >> dc >> hm >> dm;
int ci, w, a;
cin >> ci >> w >> a;
int f = 1;
for (int i = 0; i <= ci; i++)
int h = hc + i * a;
int d = dc + (ci - i) * w;
int cnt = hm / d - (hm % d == 0);
int cnt2 = h / dm - (h % dm == 0);
if (cnt <= cnt2)
cout << "YES" << endl;
f = 0;
break;
if (f) puts("NO");
return 0;
https://codeforces.com/contest/1633/problem/D
题意:a数组为全1,给定b和c数组,每次可以选定x,使a += a / x。当a=b时,可以得到价值c,问在k次操作下,可以获得的最大价值。
题解:01背包问题,预处理次数。
const int N = 1e3 + 10;
int dp[N], b[N], c[N];
int main()
memset(dp, 0x3f, sizeof dp);
dp[1] = 0;
dp[0] = 1;
for (int i = 1; i < N; i++)
for (int j = 1; j <= i; j++)
if (i + i / j < N) dp[i + i / j] = min(dp[i] + 1, dp[i + i / j]);
int t;
cin >> t;
while (t--)
memset(b, 0, sizeof b);
memset(c, 0, sizeof c);
int n, k;
cin >> n >> k;
k = min(12 * n, k);
vector<int>f(k + 1, 0);
for (int i = 1; i <= n; i++) cin >> b[i];
for (int i = 1; i <= n; i++) cin >> c[i];
for (int i = 1; i <= n; i++)
for (int j = k; j >= dp[b[i]]; j--)
f[j] = max(f[j], f[j - dp[b[i]]] + c[i]);
cout << f[k] << endl;
return 0;
以上是关于Educational Codeforces Round 122 (Rated for Div. 2) A ~ D的主要内容,如果未能解决你的问题,请参考以下文章
Educational Codeforces Round 7 A
Educational Codeforces Round 7
Educational Codeforces Round 90
Educational Codeforces Round 33