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 ...
随机推荐
- mybatispluys-Mapper CRUD 接口
Mapper CRUD 接口 通用 CRUD 封装BaseMapper (opens new window)接口,为 Mybatis-Plus 启动时自动解析实体表关系映射转换为 Mybatis 内部 ...
- Hadoop相关WebUI端口记录
以下均为默认端口号,可根据配置文件修改:HDFS:50070yarn:8088Hive:10002HBase:60010Spark:8080Flink:8081Storm:8080
- idea中设置注释颜色
1. 打开idea,右上角File-->Settings 2.找到Language Defaults-->Comments里面Block comment和Line comment 3.Bl ...
- CF-1562B- Scenes From a Memory
Problem - 1562B - Codeforces 题意:给定一个字符串,每次操作可以选择这个字符串中的一种字符,将他们全部都减1,最多K次操作,问可以形成的字典大小最小的字符串. 题解:首先我 ...
- IDEA整合Docker
创建项目 1.使用 IDEA 构建一个 SpringBoot 项目 2.编写一个helloController @RestController public class HelloController ...
- std::atomic和std::mutex区别
std::atomic介绍 模板类std::atomic是C++11提供的原子操作类型,头文件 #include<atomic>.在多线程调用下,利用std::atomic可实 ...
- Unity接入微信支付SDK 2022年版安卓篇
最近1年转了UE开发,博客更新的比较少,技术栈宽了不少,以后有空尽量多更新,也方便总结记忆 Unity接入微信支付整个过程坑比较多,网上之前的教程要么比较老,要么比较零碎,只能东拼西凑摸索,跑通后还是 ...
- Beats:Beats在Kibana中的集中管理
我们可以通过在命令行中对我们的Beats进行管理,比如我们可以启动metric几个模块,我们可以通过如下的命令来执行: ./metricbeat modules enable apache mysql ...
- 使用nginx-ingress-controller配置https,但是再同时配置使用http
默认情况下,如果为该 Ingress 启用了 TLS,控制器会使用 308 永久重定向响应将 HTTP 客户端重定向到 HTTPS 端口 443.( Ingress 里配置了 https 证书的话,默 ...
- Kubernetes ConfigMap热更新
ConfigMap是用来存储配置文件的kubernetes资源对象,所有的配置内容都存储在etcd中. 总结 更新 ConfigMap 后: 使用该 ConfigMap 挂载的 Env 不会同步更新 ...