Codeforces Round #832 (Div. 2) A~C题解
A
思路:这个题的话我们把负数和整数分别求出来,比较绝对值的大小,用较大的那个减去较小的那个就可以了。
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define int long long
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int T;
cin >> T;
while (T--)
{
int n;
cin >> n;
int zheng = 0, fu = 0;
for (int i = 1; i <= n; i++)
{
int x;
cin >> x;
if (x > 0)
zheng += x;
else
fu += x;
}
fu = abs(fu);
if (fu > zheng)
cout << fu - zheng << endl;
else
cout << zheng - fu << endl;
}
return 0;
}
B
思路:这个题一开始的时候想的是把全部的N放到前面,结果第二个测试点就WA了。其实这个题的正解是把全N和B换位置,但是有的N是不用动的,我们需要判断有几个N是不需要动的,要动的N的下标是从几开始。具体细节放在代码里。
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
void solve()
{
int n;
cin >> n;
if (n == 1)
{
cout << 1 << endl;
cout << 1 << ' ' << 3 << endl;
return ;
}
int k = n - n / 2;
cout << k << endl;
int j = 1;
for (int i = (n / 2 + 1) * 3; i <= 3 * n; i += 3)
{
cout << j << ' ' << i << endl;
j += 3;
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int T;
cin >> T;
while (T--)
{
solve();
}
return 0;
}
C
思路:这个是个博弈的题,通过观察样例的话我们可以发现,我们想要让对手输的话,我们只需要一直把那个最小的数换给他,他只能把最小的那个数-1然后换出去,所以一直反复的话最小的那个数变成0的时候,那么那个人就输了。Alice是先手没所以只要第一个不是最小的那一个那么Alice就会赢反之Bob就会赢。如果第一个和后面的最小值相等的话还是Bob赢
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 1e6 + 10;
int a[N];
void solve()
{
int Min = 0x3f3f3f3f;
int n;
cin >> n;
int sum = 0;
for (int i = 1; i <= n; i++)
{
cin >> a[i];
if (i >= 2)
Min = min(a[i], Min);
}
if (a[1] > Min)
{
cout << "Alice" << endl;
}
else
{
cout << "Bob" << endl;
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int T;
cin >> T;
while (T--)
{
solve();
}
return 0;
}
Codeforces Round #832 (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 ...
随机推荐
- shellcode 注入执行技术学习
shellcode 注入执行技术学习 注入执行方式 CreateThread CreateRemoteThread QueueUserAPC CreateThread是一种用于执行Shellcode的 ...
- 浅析websocket的基本应用spring boot + vue +C# + WPF
1.基本概念 首先websocket是基于H5的一种通信.在网页中如果定时获取服务器端的实时数据,我们常采用long poll 和ajax轮询的方式.但是在轮询过程中,由于根本没有新数据的改变,而造成 ...
- 实践分享!GitLab CI/CD 快速入门
用过 GitLab 的同学肯定也对 GitLab CI/CD 不陌生,GitLab CI/CD 是一个内置在 GitLab 中的工具,它可以帮助我们在每次代码推送时运行一系列脚本来构建.测试和验证代码 ...
- 第五十二篇:webpack的loader(三) -url-loader (图片的loader)
好家伙, 1.什么是base64? 图片的 base64 编码就是可以将一副图片数据编码成一串字符串,使用该字符串代替图像地址. 这样做有什么意义呢?我们知道,我们所看到的网页上的每一个图片,都是需要 ...
- Elasticsearch7.6.2 RestHighLevelClient查询用法 must should(and or 关系)
1. 引入jar <dependency> <groupId>org.elasticsearch.client</groupId> <artifactId&g ...
- 【读书笔记】C#高级编程 第三章 对象和类型
(一)类和结构 类和结构实际上都是创建对象的模板,每个对象都包含数据,并提供了处理和访问数据的方法. 类和结构的区别:内存中的存储方式.访问方式(类是存储在堆上的引用类型,结构是存储在栈的值类型)和它 ...
- 【项目实战】用Pytorch实现线性回归
视频教程:https://www.bilibili.com/video/BV1Y7411d7Ys?p=5 准备数据 首先配置了环境变量,这里使用python3.9.7版本,在Anaconda下构建环境 ...
- 开源 Web 相册程序: Photoview 和数据可视化生成工具:Datawrapper
Photoview Photoview是一个开源 Web 相册程序,Go 语言写的,使用 Docker 安装,可以用来快速架设个人相册. github地址:https://github.com/pho ...
- es,logstash各版本对应要求的JDK版本,操作系统对应示意图
官网地址:https://www.elastic.co/cn/support/matrix
- 一文搞懂容器运行时 Containerd
文章转载自:https://www.qikqiak.com/post/containerd-usage/ 在学习 Containerd 之前我们有必要对 Docker 的发展历史做一个简单的回顾,因为 ...