Codeforces Round #700 (Div. 2) A~C题解
写在前边
A. Yet Another String Game
链接:A题链接
题目大意:
给定一个字符串,有两位同学来操作这个字符串,一个同学负责使得字符串字典序变大,另一个同学负责使得字符串字典序变小,轮到他们的时候他们无论如何都要操作一次,如果当前字符是\('a'\),那么即使轮到了负责使字典序变小的同学来操作,他也要将其变成'b',求最后的字符串。
思路:
模拟即可,遇到\('a'\),\('z'\)字符特判一下。
代码:
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <map>
#include <cstring>
using namespace std;
#define Inf 0x3f3f3f3f
#define PII pair<int, int>
#define P2LL pair<long long, long long>
#define endl '\n'
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<long long> VLL;
typedef vector<int> VI;
void solve() {
string s, res = "";
cin >> s;
for (int i = 0; i < s.size(); i++) {
if (i % 2 == 0) { //Alice
res += (s[i] == 'a' ? 'b' : 'a');
} else {
res += (s[i] == 'z' ? 'y' : 'z');
}
}
cout << res << endl;
}
int main()
{
//ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
int t;
scanf("%d", &t);
while (t--) {
solve();
}
system("pause");
return 0;
}
B. The Great Hero
链接:B题链接
题目大意:
英雄打怪兽,没有谁先手之分,英雄与怪兽都有血量与攻击力,并且都会收到对方的伤害,攻击的顺序不限,判断最后英雄是否能干掉所有怪兽,即使英雄牺牲也算。
思路:
这种题目常规思路真的很难搞,很容易就出现一些浮点问题,而且还所以不如我们可以先预处理出如果英雄能干掉所有的怪兽所需要的\(HP\)记为\(sum\),然后想,我们如果可以用最少的血量干掉血量多伤害大的怪兽那肯定血赚,比如我们的攻击是\(7\),初始血量为\(8\),这时候有一个攻击力为\(8\)的怪兽,血量为\(7\),如果我们最先攻击这只怪兽,那么我们就与其同归于尽了,其他的怪兽就打不了了,所以收益很低,而我们如果干掉其他所有怪物后再最后攻击这只怪物,还剩下一点血的时候,与其同归于尽收益肯定更大,而这一步排序不容易实现,所以我们可以考虑一下英雄的最后一击,如果英雄的最后一击之前有血量大于\(0\),那么说明英雄就可以完美干掉所有怪物,所以我们可以枚举所有小怪的攻击力,判断\(sum - attack[i] < 英雄HP\)如果出现就说明我们一定可以按照一定的顺序去干掉所有的怪兽,而这个顺序是什么我们不需要在意,时间复杂度\(O(n)\)。
代码:
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <map>
#include <cstring>
using namespace std;
#define Inf 0x3f3f3f3f
#define PII pair<int, int>
#define P2LL pair<long long, long long>
#define endl '\n'
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<long long> VLL;
typedef vector<int> VI;
const int N = 1E5 + 10;
int attack[N], hp[N];
int Attack, HP, n;
int cost[N]; //干掉每只怪花的力气
void solve() {
scanf("%d%d%d", &Attack, &HP, &n);
for (int i = 0; i < n; i++) scanf("%d", &attack[i]);
for (int i = 0; i < n; i++) scanf("%d", &hp[i]);
LL sum = 0;
for (int i = 0; i < n; i++) sum += (LL)(hp[i] + Attack - 1) / Attack * attack[i]; //承受攻击
for (int i = 0; i < n; i++) {
if (sum - attack[i] < HP) {
puts("YES");
return;
}
}
puts("NO");
}
int main()
{
//ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
int t, cnt = 1;
scanf("%d", &t);
int q = t;
while (t--) {
solve();
}
system("pause");
return 0;
}
C. Searching Local Minimum
链接:C题链接
题目大意:
一道交互题。
思路:
第一次听说这种类型的题目,现在也还是懵懵了,大概就是输出会被机器获取当成输入,输出称为机器的输入,对于这道一而言,我们就是维护一个\([l,r]\)区间最后趋于一个点,并且满足,\(a_{r + 1} > a_r\), \(a_{l - 1} < a_{l}\),这个点就是答案,于是用二分来实现,对于\(a[mid] < a[mid] + 1\),让\(r = mid\),反之\(l = mid + 1\)
代码:
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <map>
#include <cstring>
using namespace std;
#define Inf 0x3f3f3f3f
#define PII pair<int, int>
#define P2LL pair<long long, long long>
#define endl '\n'
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<long long> VLL;
typedef vector<int> VI;
LL gcd(LL a, LL b) {
return b ? gcd(b, a % b) : a;
}
const int N = 1E5 + 10;
int a[N];
int n;
void query(int x) {
if (x >= 1 && x <= n) {
printf("? %d\n", x);
fflush(stdout);
scanf("%d", &a[x]);
}
}
void solve() {
scanf("%d", &n);
a[0] = a[n + 1] = 1e9;
int l = 1, r = n;
while (l < r) {
int mid = l + r >> 1;
query(mid);
query(mid + 1);
if (a[mid] < a[mid + 1]) r = mid;
else l = mid + 1;
}
printf("! %d\n", l);
fflush(stdout);
}
int main()
{
//ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
solve();
system("pause");
return 0;
}
另外一道交互题A. Bear and Prime 100.
题目大意:
我们会对系统进行询问,如果我们询问的数是那个隐藏的数的约数,那么系统会回答\(yes\),要求在二十次询问之内,判断出隐藏的数是否为质数,例如:那个隐藏的数为\(14\),那么我们如果打印\(2,7\)或者\(14\),系统都会回答\(yes\)。
思路:
我们要做的就是枚举所有可能的质因数,然后根据系统的回答来判断那个隐藏的数的约数个数,从而判断它是否为约数。
首先根据算术基本定理,如果一个数是合数,那么它一定可以被唯一的分解成两个或两个以上的质数的积,因此最后20次询问之后只需要判断出是否有两个或两个以上的质数,所以我们要做的就是要考虑枚举哪些数才能在确保二十次询问之内判断出一个\(\in [1, 100]\)的数。
首先我们仅仅需要考虑50之内的质数,因为判断\(n\)是否为质数的一种方式就是枚举到\(\cfrac{n}{2}\)即可,结合实际如果有一个大于\(50\)的质数,那么它与最小的质数相乘也大于\(100\)了,那么现在就有了\(2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47\)十五个数。
还要想到一些特例,质数的平方,\(4,9,36,49\)这四个数,所以总共就有\(19\)个数了,因此我们完全可以在\(20\)次询问之内判断出一个数是否为质数了
代码:
#include <cstdio>
#include <vector>
#include <map>
#include <cstring>
using namespace std;
#define Inf 0x3f3f3f3f
#define PII pair<int, int>
#define P2LL pair<long long, long long>
#define endl '\n'
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<long long> VLL;
typedef vector<int> VI;
LL gcd(LL a, LL b) {
return b ? gcd(b, a % b) : a;
}
int primes[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 4, 9, 25, 49};
void solve() {
int cnt = 0;
char s[10];
for (int i = 0; i < 19; i++) {
cout << primes[i] << endl;
cin >> s;
if (!strcmp(s, "yes")) cnt++;
}
if (cnt >= 2) cout << "composite" << endl;
else cout << "prime" << endl;
}
int main()
{
//ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
solve();
return 0;
}
Codeforces Round #700 (Div. 2) A~C题解的更多相关文章
- Codeforces Round #612 (Div. 2) 前四题题解
这场比赛的出题人挺有意思,全部magic成了青色. 还有题目中的图片特别有趣. 晚上没打,开virtual contest打的,就会前三道,我太菜了. 最后看着题解补了第四道. 比赛传送门 A. An ...
- Codeforces Round #198 (Div. 2)A,B题解
Codeforces Round #198 (Div. 2) 昨天看到奋斗群的群赛,好奇的去做了一下, 大概花了3个小时Ak,我大概可以退役了吧 那下面来稍微总结一下 A. The Wall Iahu ...
- Codeforces Round #672 (Div. 2) A - C1题解
[Codeforces Round #672 (Div. 2) A - C1 ] 题目链接# A. Cubes Sorting 思路: " If Wheatley needs more th ...
- Codeforces Round #614 (Div. 2) A-E简要题解
链接:https://codeforces.com/contest/1293 A. ConneR and the A.R.C. Markland-N 题意:略 思路:上下枚举1000次扫一遍,比较一下 ...
- Codeforces Round #610 (Div. 2) A-E简要题解
contest链接: https://codeforces.com/contest/1282 A. Temporarily unavailable 题意: 给一个区间L,R通有网络,有个点x,在x+r ...
- Codeforces Round #611 (Div. 3) A-F简要题解
contest链接:https://codeforces.com/contest/1283 A. Minutes Before the New Year 题意:给一个当前时间,输出离第二天差多少分钟 ...
- Codeforces Round #499 (Div. 2) D. Rocket题解
题目: http://codeforces.com/contest/1011/problem/D This is an interactive problem. Natasha is going to ...
- Codeforces Round #499 (Div. 2) C Fly题解
题目 http://codeforces.com/contest/1011/problem/C Natasha is going to fly on a rocket to Mars and retu ...
- Codeforces Round #198 (Div. 2)C,D题解
接着是C,D的题解 C. Tourist Problem Iahub is a big fan of tourists. He wants to become a tourist himself, s ...
- Codeforces Round #579 (Div. 3) 套题 题解
A. Circle of Students 题目:https://codeforces.com/contest/1203/problem/A 题意:一堆人坐成一个环,问能否按逆时针或者顺时针 ...
随机推荐
- 数据处理的那些事「GitHub 热点速览」
撇开一屏占四分之三屏幕的 AI 相关项目之外,本周剩下的热榜项目就是同数据有关的数据库项目,比如 CockroachDB 团队开源的 kv 存储数据库 pebble,旨在提供高性能的消息队列 blaz ...
- Oracle 11gR2 单实例 For linux6
第一章 准备工作 1.1 系统硬件和软件环境检查 Ø 物理内存至少1G # grep MemTotal /proc/meminfo Ø swap物理内存小于2G时设置为物理内存 ...
- AcWing 4799. 最远距离题解
请看: 我们规定,如果一个无向连通图满足去掉其中的任意一条边都会使得该图变得不连通,则称该图为有效无向连通图. 去掉一条边就不连通了,这不就是树吗? (否则如果是图(就是不是树的图)的话,一定有环,拆 ...
- [django]数据的导入和导出
除了使用mysqldump或者MySQL客户端进行数据导出,django也提供了类似的功能. 导出 # 导出整个数据库并保存为json文件 python manage.py dumpdata > ...
- P1551 亲戚 && #569. 【例4-7】亲戚(并查集)
P1551 亲戚 题目链接:落谷 题目链接:TFLS OJ 落谷题解(具体分析见慎入潜出P239) #include<bits/stdc++.h> using namespace std; ...
- CTFshow misc1-10
小提示:需要从图片上提取flag文字,可以通过截图翻译或者微信发送图片,这两个的ai图像识别挺好用的. misc1: 解压打开就能看见flag,提取出来就行 misc2: 记事本打开,看见 ng字符, ...
- Pandas 使用教程 CSV
CSV(Comma-Separated Values,逗号分隔值,有时也称为字符分隔值,因为分隔字符也可以不是逗号),其文件以纯文本形式存储表格数据(数字和文本). CSV 是一种通用的.相对简单的文 ...
- PyCharm的基础了解
简单了解PyCharm PyCharm的简单使用 修改主题 1 2 切换解释器 1 如何创建pythin文件 1 2 3 4 注释语法 行注释 这里是注释 块注释 '''这里是注释''' 常量和变量的 ...
- 数据api接口就是应用集成吗?
数据 API 接口和应用集成是两个不同的概念,但是它们之间有一定的联系.数据 API 接口是一种用于访问和传输数据的标准化接口,而应用集成则是将不同的应用程序和系统整合在一起,实现数据和业务流程的 ...
- xlsx和path的运用
从后端获取Excel模板 app.get('/api/download-template', (req, res) => { const templatePath = path.join(__d ...