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 题意:一堆人坐成一个环,问能否按逆时针或者顺时针 ...
随机推荐
- 管理虚拟环境——virtualenvwrapper
1.安装virtualenvwrapper 输入命令:pip install -i https://pypi.douban.com/simple/ virtualenv //下载virtualenvw ...
- QLabel标签快捷键的使用
1 from PyQt5.QtWidgets import * 2 import sys 3 4 class QlabelDemo(QDialog): 5 def __init__(self): 6 ...
- LaZagne:一键抓取目标机器上的所有明文密码的神器
LaZagne 介绍 功能 LaZagne 是用于获取存储在本地计算机上的大量密码的开源应用程序. 每个软件都使用不同的技术(纯文本.API.自定义算法.数据库等)存储其密码.LaZagne 的作用就 ...
- 实在智能TARS-RPA-Agent,业界首发的产品级大模型Agent有何非凡之处?
融合LLM的RPA进化到什么程度? AIGC如何借AI Agent落地? 像生成文本一样生成流程的ChatRPA,能够提升RPA新体验? 边探索边创建的ChatRPA,能否破解RPA与LLM融合难题? ...
- .NET周刊【8月第3期 2023-08-20】
国内主题 抓的是周树人,与我鲁迅有什么关系? https://www.cnblogs.com/JulianHuang/p/17642511.html 问题:作者看到了一个关于Dictionary.Cl ...
- fastapi启动后访问docs不显示页面的问题
笔者之前正常使用fastapi的docs接口进行各种接口调试,使用很正常,之前安装也都是正常安装流程,没有做任何修改,可以突然有一天不知道为啥,docs接口打开是空白的,接口也没有报错,就是空白,摸索 ...
- 使用pycharm脚本发送钉钉群通知
使用Pychon脚本发送钉钉群通知 我们可以使用钉钉的机器人助手发送群通知,只需要非常简单的配置就可以实现,而没有任何的成本. 1) 首先我们要在钉钉群里添加一个机器人助手 选择智能群助手,然后选择添 ...
- Dami 本地过程调用框架(主打解耦),v0.24 发布
Dami,专为本地多模块之间通讯解耦而设计(尤其是未知模块.隔离模块.领域模块).零依赖,特适合 DDD. 特点 结合 Bus 与 RPC 的概念,可作事件分发,可作接口调用,可作异步响应. 支持事务 ...
- 🖖少年,该升级 Vue3 了!
你好,我是 Kagol. 前言 根据 Vue 官网文档的说明,Vue2 的终止支持时间是 2023 年 12 月 31 日,这意味着从明年开始: Vue2 将不再更新和升级新版本,不再增加新特性,不再 ...
- Solution -「HNOI 2016」最小公倍数(lacks of code)
Description Link. 给出一个带权无向图,边权为 \(2^{a}\cdot3^{b}\) 形式. 给出 \(q\) 组形如 \(u,v,a,b\) 的询问,问 \(u,v\) 中是否存在 ...