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的木板,现在你可以随便抽几个拼在一起,然后你要从这一 ...
随机推荐
- SpringBoot进阶教程(七十八)邮件服务
Sun公司提供了JavaMail用来实现邮件发送,但是配置烦琐,Spring中提供了JavaMailSender用来简化邮件配置,Spring Boot则提供了MailSenderAutoConfig ...
- Tomcat国内安装及乱码解决详细步骤(无f墙)
1.下载安装包 链接:https://pan.baidu.com/s/1x_hWMnUrui4aDYo9UE-GdA?pwd=p8kn 提取码:p8kn --来自百度网盘超级会员V4的分享 2.一键下 ...
- Pattern类和Matcher类的使用
1.先看好数据源 先将一个String对象确定为程序要对其进行操作的数据源. String b="hello,good morning"; 2.建立Pattern类的对象 Stri ...
- [ABC262A] World Cup
Problem Statement A sport event is held in June of every year whose remainder when divided by $4$ is ...
- MySQL运维8-Mycat范围分表
一.范围分片 根据指定的字段及其配置的范围与数据节点的对应情况,来决定该数据属于哪一个分片. 说明1:范围分片会提前提供一个分片的范围默认是0-500万是一个分片,500万-1000万是一个分片,10 ...
- 文心一言 VS 讯飞星火 VS chatgpt (159)-- 算法导论12.3 6题
六.用go语言,当 TREE-DELETE 中的结点 z 有两个孩子时,应该选择结点 y 作为它的前驱,而不是作为它的后继.如果这样做,对 TREE-DELETE 应该做些什么必要的修改?一些人提出了 ...
- ElasticSearch之cat plugins API
命令样例如下: curl -X GET "https://localhost:9200/_cat/plugins?v=true&pretty" --cacert $ES_H ...
- 一个WPF版的Layui前端UI库
前言 相信做.NET后端开发的很多小伙伴都用过Layui前端UI组件库,今天我们分享一个WPF版的Layui前端UI样式库:Layui-WPF. WPF介绍 WPF 是一个强大的桌面应用程序框架,用于 ...
- JavaFx之使用高版本JDK(二十八)
JavaFx之使用高版本JDK(二十八) 如何使用高版本的jfx? 根据官网的需要手动引入jfx模块(运行参数:–module-path) 要知道高版本jfx已经集成了丰富的主流功能,例如视频编码,大 ...
- 文心一言 VS 讯飞星火 VS chatgpt (177)-- 算法导论13.3 6题
六.用go语言,说明如果红黑树的表示中不提供父指针,应当如何有效地实现 RB-INSERT. 文心一言: 红黑树是一种自平衡的二叉搜索树,其中每个节点都包含一个颜色属性(红色或黑色),并且满足以下性质 ...