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 题意:一堆人坐成一个环,问能否按逆时针或者顺时针 ...
随机推荐
- [C#]WPF 分辨率的无关性的问题
什么是WPF的分辨率无关性? 首先得解什么是Dpi(Density independent pixels ,设备无关像素),百度百科的解释DPI是指每英寸的像素,对应界面显示即是屏幕上每英寸的像素. ...
- Fastjson1.2.24漏洞复现-基于vulhub漏洞平台(文件上传写入-反弹shell)
Fastjson1.2.24漏洞复现-基于vulhub漏洞平台 环境准备: 192.168.59.130 攻击机 window10 192.168.59.135 靶机 centos8 声明:不涉及互联 ...
- 利用选项卡提高Visual Studio 2022开发效率
设计器作为软件开发的必要工具,其效率的提高显得尤为重要.Visual Studio 2022作为一款功能强大的设计器,通过选项卡提高了工作效率,让开发者在使用过程中更加便捷. 在Visual Stud ...
- [nginx]定制http头信息
前言 修改http响应头信息,相关Nginx模块:ngx_http_headers_module expires 语法: expires [modified] time; expires [modif ...
- 二代水务系统架构设计分享——DDD+个性化
系统要求 C/S架构的单体桌面应用,可以满足客户个性化需求,易于升级和维护.相比于一代Winform,界面要求美观,控件丰富可定制. 解决方案 依托.Net6开发平台,采用模块化思想设计(即分而治之的 ...
- 使用C++界面框架ImGUI开发一个简单程序
目录 简介 使用示例 下载示例 main文件 设置ImGui风格 设置字体 主循环 添加Application类 中文编码问题 界面设计 关于imgui_demo.cpp 创建停靠空间 创建页面 隐藏 ...
- Kettle实例(获取Token并带入请求接口拉取数据到本地)
背景 近期工作中遇到许多需要协同的表单文档被放到云文档,那么我们本地做数据分析就需要先抽取云文档实时数据到本地数据库,根据接口文档我们需要先获取Token,再将返回值带到接口中发起请求拉取数据,因为在 ...
- Kurator,你的分布式云原生解决方案
本文分享自华为云社区<DTSE Tech Talk | 第40期:Kurator,你的分布式云原生解决方案>,作者:华为云社区精选. 什么是分布式云原生? 中国信通院给出的定义:分布式云原 ...
- Jitpack发布Android库带文档和源码
原文地址: Jitpack发布Android库带文档和源码 - Stars-One的杂货小窝 忽然发现自己发布的xAndroidUtil库 写代码的时候看方法注释都看不到,研究了下如何让Jitpack ...
- Elasticsearch之常用术语
一. 数据库和ES简单类比 关系型数据库 表(Table) 行(Row) 列(Cloumn) Schema SQL Elasticsearch 索引(Index) 文档(Document) 字段(Fi ...