Codeforces Round #700 (Div. 2) A ~ D1个人题解
Codeforces Round #700 (Div. 2)
比赛链接: Click Here
1480A. Yet Another String Game
因为Alice是要追求小,Bob追求大值,所以只要变为 a 或 z.
AC代码
int main() {
ios_base::sync_with_stdio(false), cin.tie(0);
for (cin >> _; _--;) {
string s;
cin >> s;
for (int i = 0; i < s.size(); ++i)
if (i % 2 == 0) {
if (s[i] == 'a') cout << 'b';
else cout << 'a';
} else {
if (s[i] != 'z') cout << 'z';
else cout << 'y';
}
cout << "\n";
}
return 0;
}
1480B. The Great Hero
排序,对英雄伤害少的排前面,统计总共打败的敌人数即可
AC代码
using ll = long long;
int _;
struct node {
ll a, b;
};
ll A, B;
bool cmp(node a, node b) {
ll d1 = (a.b / A + a.b % A != 0) * a.a, d2 = (b.b / A + b.b % A != 0) * b.a;
return d1 < d2;
}
int main() {
ios_base::sync_with_stdio(false), cin.tie(0);
for (cin >> _; _--;) {
int n, cnt = 0;
cin >> A >> B >> n;
vector<node> e(n);
for (int i = 0; i < n; ++i) cin >> e[i].a;
for (int i = 0; i < n; ++i) cin >> e[i].b;
sort(e.begin(), e.end(), cmp);
for (int i = 0; i < n; ++i) {
while (B >= 1 && e[i].b >= 1) e[i].b -= A, B -= e[i].a;
if (e[i].b <= 0) cnt++;
}
cout << (cnt == n ? "YES\n" : "NO\n");
}
return 0;
}
1480C. Searching Local Minimum
C题没做出来,待补。
1480D1. Painting the Array I
题意和思路来自网络

个人理解以后的AC代码
int _;
int a[210000];
int main() {
ios_base::sync_with_stdio(false), cin.tie(0);
int n;
cin >> n;
for (int i = 1; i <= n; ++i) cin >> a[i];
int lst = 0, sum = 0;
for (int i = 1; i <= n; ++i) {
if (a[i] == a[i + 1]) {
if (a[lst] != a[i])
sum += 2;
else {
bool f = false;
for (int j = i - 1; true; --j) {
if (a[j] != a[i] && a[j + 1] != a[i]) {
f = true;
break;
}
if (j == lst) break;
}
sum += f ? 2 : 1;
}
while (a[i] == a[i + 1]) ++i;
lst = i;
} else
sum++;
// cout << sum << "\n";
}
cout << sum << "\n";
return 0;
}
1480D2. Painting the Array II
D2昨天没啥想法就被弃掉了(老菜鸡了)
顺便贴一下朋友的D2代码
AC代码
int _;
int a[100005], b[100005], ans[100005], now[100005], pre[100005];
int dfs(int x) {
if (ans[x] != -1) return ans[x];
if (x == 0) return 0;
ans[x] = dfs(x - 1);
if (pre[x]) ans[x] = max(ans[x], dfs(pre[x] + 1) + 1);
return ans[x];
}
int main() {
int T = 1;
// cin>>T;
while (T--) {
int n, x = 0;
cin >> n;
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
for (int i = 1; i <= n; i++)
if (a[i] != a[i - 1]) b[++x] = a[i];
for (int i = 1; i <= x; i++) pre[i] = now[b[i]], now[b[i]] = i;
memset(ans, -1, sizeof(ans));
dfs(x);
int mx = 0;
for (int i = 1; i <= x; i++) mx = max(mx, ans[i]);
cout << x - mx << endl;
}
return 0;
}
Codeforces Round #700 (Div. 2) A ~ D1个人题解的更多相关文章
- Codeforces Round #609 (Div. 2)前五题题解
Codeforces Round #609 (Div. 2)前五题题解 补题补题…… C题写挂了好几个次,最后一题看了好久题解才懂……我太迟钝了…… 然后因为longlong调了半个小时…… A.Eq ...
- Codeforces Round #741 (Div. 2), problem: (D1) Two Hundred Twenty One (easy version), 1700
Problem - D1 - Codeforces 题意: 给n个符号(+或-), +代表+1, -代表-1, 求最少删去几个点, 使得 题解(仅此个人理解): 1. 这题打眼一看, 肯定和奇 ...
- Codeforces Round #700 (Div. 2) --- B(思维)
传送门 有必要提醒自己一下, 先把题读利索了(手动捂脸) 题目 B. The Great Hero The great hero guards the country where Homer li ...
- Codeforces Round #556 (Div. 2) D. Three Religions 题解 动态规划
题目链接:http://codeforces.com/contest/1150/problem/D 题目大意: 你有一个参考串 s 和三个装载字符串的容器 vec[0..2] ,然后还有 q 次操作, ...
- Codeforces Round #604 (Div. 2) E. Beautiful Mirrors 题解 组合数学
题目链接:https://codeforces.com/contest/1265/problem/E 题目大意: 有 \(n\) 个步骤,第 \(i\) 个步骤成功的概率是 \(P_i\) ,每一步只 ...
- Codeforces Round #624 (Div. 3) F. Moving Points 题解
第一次写博客 ,请多指教! 翻了翻前面的题解发现都是用树状数组来做,这里更新一个 线段树+离散化的做法: 其实这道题是没有必要用线段树的,树状数组就能够解决.但是个人感觉把线段树用熟了会比树状数组更有 ...
- Codeforces Round #677 (Div. 3) E、G题解
E. Two Round Dances #圆排列 题目链接 题意 \(n\)(保证偶数)个人,要表演一个节目,这个节目包含两种圆形舞蹈,而每种圆形舞蹈恰好需要\(n/2\)个人,每个人只能跳一种圆形舞 ...
- Codeforces Round#402(Div.1)掉分记+题解
哎,今天第一次打div1 感觉头脑很不清醒... 看到第一题就蒙了,想了好久,怎么乱dp,倒过来插之类的...突然发现不就是一道sb二分吗.....sb二分看了二十分钟........ 然后第二题看了 ...
- Codeforces Round #604 (Div. 2) 练习A,B题解
A题 链接 思路分析: 因为只需要做到相邻的不相同,利用三个不同的字母是肯定可以实现的, 所以直接先将所有的问号进行替换,比如比前一个大1,如果与后面的冲突,则再加一 代码(写的很烂): #inclu ...
- Codeforces Round #599 (Div. 2)的简单题题解
难题不会啊…… 我感觉写这个的原因就是因为……无聊要给大家翻译题面 A. Maximum Square 简单题意: 有$n$条长为$a_i$,宽为1的木板,现在你可以随便抽几个拼在一起,然后你要从这一 ...
随机推荐
- 【Javaweb】五(Service类)
一般Spring项目中处理业务的层为Service层,称为业务层.目前常见的风格有: 写法:Service层=Service接口+ServiceImpl实现类 AdminServiceImpl.jav ...
- [ABC311G] One More Grid Task
Problem Statement There is an $N \times M$ grid, where the square at the $i$-th row from the top and ...
- idea用不了 idea.bat文件闪退
由于idea的智能,在破解之后会留下一些问题,根据网上搜出来的解决办法. 1.C:\Users\dell\AppData\Roaming\JetBrains\IntelliJIdea2022.2 在这 ...
- MySQL索引命名规范
[强制]主键索引名为 pk_字段名:唯一索引名为 uk_字段名:普通索引名则为 idx_字段名 说明:pk_ 即 primary key:uk_ 即 unique key:idx_ 即 index 的 ...
- 算法1:Fibonacci数列
斐波那契数列(Fibonacci) 一.背景介绍 斐波那契数列(Fibonacci sequence),又称黄金分割数列,因数学家莱昂纳多·斐波那契(Leonardo Fibonacci)以兔子繁殖为 ...
- selenium之三种等待,强制等待、隐式等待和显式等待
显式等待 presence_of_element_locatedpresence_of_all_elements_locatedvisibility_of_any_elements_located ...
- Ef Core花里胡哨系列(10) 动态起来的 DbContext
Ef Core花里胡哨系列(10) 动态起来的 DbContext 我们知道,DbContext有两种托管方式,一种是AddDbContext和AddDbContextFactory,但是呢他们各有优 ...
- 部署堡垒机6——配置Nginx及其他组件
Lina部署 cd /opt wget https://github.com/jumpserver/lina/releases/download/v2.28.7/lina-v2.28.7.tar.gz ...
- 一个简单的Python暴力破解网站登录密码脚本
目录: 关键代码解释 完整代码 方法一 运行结果 方法二 运行结果 测试靶机为DVWA,适合DVWA暴力破解模块的Low和Medium等级 关键代码解释 url指定url地址 url = " ...
- Ubuntu 之 7zip使用
1.安装 sudo apt-get install p7zip 2.压缩 7zr a xxx foldername 3.解压缩 7zr x xxx.7z 4.zip命令压缩文件夹 zip -qr xx ...