Codeforces Round #698 (Div. 2) A~C题解
写在前边
链接:Codeforces Round #698 (Div. 2)
又是自闭的一场比赛,\(C\)题补了一天终于明白了一些,真的好自闭好自闭。
今晚还有一场,加油喽。
A. Nezzar and Colorful Balls
链接:A题链接
题目大意:
给定一个单调不减的序列,现在往上边涂颜色,要求涂颜色后,选中其中任意一种颜色,去除所有其他颜色的数字后剩下的数字组成的序列是严格递增的,问至少需要几种颜色可以达到这种效果。
思路:
首先想到,如果想要达到题目要求,对于这类似1 1 1 1这种连续相同的序列,肯定不能用一种颜色,因子就推出需要的颜色种数就是序列中数目最多的数字个数。
代码:
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <unordered_map>
using namespace std;
#define Inf 0x3f3f3f3f
#define PII pair<int, int>
#define P2LL pair<long long, long long>
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<long long> VLL;
typedef vector<int> VI;
void solve() {
int n;
cin >> n;
unordered_map<int, int> hash;
for (int i = 0; i < n; i++) {
int c;
cin >> c;
hash[c]++;
}
int res = 0;
for (auto it : hash) {
res = max(res, it.second);
}
cout << res << endl;
}
int main()
{
//ios::sync_with_stdio(false), cin.tie(0);
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}
B. Nezzar and Lucky Number
链接:B题链接
题目大意:
选定一个幸运数\(d \in [1, 9]\),凡是数字中带有它都是幸运数,如选定\(7\),那么\(17,27...\)也都是幸运数,同时,由幸运数加和组成的数也都是幸运数,例如\(54 = 27 + 27\),因此\(54\)也是幸运数,现在要求快速判断一个数是否是幸运数。
思路:
推了好久,一个数如果是幸运数,大致推出一个数是幸运数那么必然可以表示:\(number = 10 * k + d * n, k \geq 0, d \geq 1\)的形式,因此判断一个数是否是幸运数就让它一直减d,直到剩下\(\geq 0\)个\(10\),那么就可以判断是幸运数了,但是对于大数这样做铁定超超时,而对于大数,还有一条性质,即如果\(number\geq10*d\),那么\(number\)必然是一个幸运数,下面给出证明:
设一个区间:\([10*d, 10*d + 9]\)
那么对于这样一个区间的数就包含了一个\(d\)了,因此这个区间的数就都是幸运数,而对于每一个数\(k > 10*d + 9\),我们可以让它不断地减去\(d\)那么一定可以落到这个区间,因此\(number\geq10*d\),则\(number\)一定是幸运数,证毕。
所以对于大数可以直接判断是否\(≥10*d\),小数直接枚举即可。
代码:
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <unordered_map>
#include <string>
using namespace std;
#define Inf 0x3f3f3f3f
#define PII pair<int, int>
#define P2LL pair<long long, long long>
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<long long> VLL;
typedef vector<int> VI;
const int N = 1E4 + 10;
int a[N];
void solve() {
int q, d, idx;
scanf("%d%d", &q, &d);
for (int i = 0; i < q; i++) {
scanf("%d", &a[i]);
}
for (int i = 0; i < q; i++) {
if (a[i] >= 10 * d) {
puts("YES");
} else {
int temp = a[i];
temp -= d;
//一直减d减到10的倍数
while (temp % 10 != 0 && temp >= 0) {
temp -= d;
}
if (temp >= 0 && temp / 10 >= 0) {
puts("YES");
} else {
puts("NO");
}
}
}
}
int main()
{
//ios::sync_with_stdio(false), cin.tie(0);
int t;
scanf("%d", &t);
while (t--) {
solve();
}
return 0;
}
C. Nezzar and Symmetric Array
链接:C题链接
题目大意:
给定一个有\(2*n\)个数数组\(d_i\),问我们是否可以构造出一个\(a_i\),\(a\)满足以下条件:
- \(a\)中\(2*n\)个数各不相同。
- 对于任意一个数,\(1 \leq i \leq 2n\),存在一个数\(1 \leq j \leq 2n\),这两个数满足\(a_i = -a_j\)。
能使得\(d_i = \sum\limits_{j = 1}^{2n} |a_i - a_j|\)
思路:
\(a\)中的数可以说是"对称"的,即一正一负,对于一个数对\(x\)与其中一个数对\((y, -y)\)就有\(|x-y| + |x + y|\),同理对于\(-x\)则有\(|-x-y| + |-x + y|\),而\(|x-y| + |x + y| = |-x-y| + |-x + y|\),所以可见\(d\)中得数对是成对出现的,同时\(a_i\)又是两两不同,那么\(d\)中相同的数的对数只能为\(1\),且不能超过\(1\),又因为任意两个相同的数相加是一定偶数,因此d中的数肯定都是偶数, 所以对于\(|x-y| + |x + y|\):
当\(x > y\)时,则\(|x-y| + |x + y| = 2 * x\)
当\(x < y\)时,则\(|x-y| + |x + y| = 2 * y\)
因此可以发现对于一个\(x\)与一个数对\((y, -y)\),对\(d_i\)得贡献就是\(|x-y| + |x + y| = 2 * max(x, y)\), 同理\(-x\)也是。
所以对于题目中所给公式\(d_i = \sum\limits_{j = 1}^{2n} |a_i - a_j|\),公式就变成了\(d_i = \sum\limits_{j = 1}^{2n} max(|a_i|, |a_j|)\),而又因为\(x\)与\(-x\)对\(d_i\)的贡献相同,因此我们光看正的那一部分,所以公式又变成了\(d_i = 2 * \sum\limits_{j = 1}^{n} max(|a_i|, |a_j|)\)。
对于最大的数\(a_i\)那么组成的\(d_i\)肯定也是最大的,\(d_i = a[i] * 2 * n\),所以得\(a[i] = \cfrac{d_i}{2 * n}\)
对于次大的数\(a_{i-1}\),因为比它大的只有\(a_i\),所以\(d_{i - 1} = a[i - 1] * 2 * (n - 1) + 2 * a[i]\),即\(a[i - 1] = \cfrac{d_{i - 1} - 2 * a[i]}{2 * (n - 1)}\)
\(...\)
以此类推,还要判断一下计算出来的\(a\)是否已经存在, 或者其他情况。
代码:
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <map>
using namespace std;
#define Inf 0x3f3f3f3f
#define PII pair<int, int>
#define P2LL pair<long long, long long>
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<long long> VLL;
typedef vector<int> VI;
typedef long long LL;
const int N = 1E5 + 10;
LL n;
void solve() {
cin >> n;
map<LL, LL, greater<int> > mp;
map<LL, bool> vis;
for (int i = 0; i < n * 2; i++) {
LL c;
cin >> c;
mp[c]++;
}
LL k = 0, last = 0;
for (auto it : mp) {
LL d_value = it.first, cnt = it.second;
if (cnt & 1 || d_value & 1 || cnt > 2) { //如果没有成对出现 或者 出现奇数 出现次数大于2
puts("NO");
return;
}
LL up = (d_value - last * 2) / 2;
LL down = n - k;
if (up % down != 0) {
puts("NO");
return;
}
up /= down;
if (vis.count(up) || up <= 0) {
puts("NO");
return;
}
vis[up] = true;
last += up;
k++;
}
puts("YES");
}
int main()
{
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int t;
cin >> t;
while (t--) {
solve();
}
system("pause");
return 0;
}
Codeforces Round #698 (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 题意:一堆人坐成一个环,问能否按逆时针或者顺时针 ...
随机推荐
- VScode 中golang 单元测试,解决单元测试超时timeout30s
目的:单元测试的主要目的是验证代码的每个单元(函数.方法)是否按照预期工作. 提示:解决单元测试超时30s的问题在序号4 1 准备以_test.go结尾文件和导入testing包 在命名文件时需要让文 ...
- C#程序的启动显示方案(无窗口进程发送消息) - 开源研究系列文章
今天继续研究C#的WinForm的实例显示效果. 我们上次介绍了Winform窗体的唯一实例运行代码(见博文:基于C#的应用程序单例唯一运行的完美解决方案 - 开源研究系列文章 ).这就有一个问题,程 ...
- CentOS系统修改yum源
看了一下自己之前写的文章,写的那叫一个垃圾.无地自容.作为一个菜鸡.现在不妨在博客上记录一下自己学习的记录,同时发表出来,也算作是对自己的勉励. 吾辈不孤,吾道不寡,诸君加油! 下面进入正题: Cen ...
- nlp入门(三)基于贝叶斯算法的拼写错误检测器
源码请到:自然语言处理练习: 学习自然语言处理时候写的一些代码 (gitee.com) 数据来源:norvig.com/big.txt 贝叶斯原理可看这里:机器学习算法学习笔记 - 过客匆匆,沉沉浮浮 ...
- 【opencv】传统图像识别:hog+svm实现图像识别详解
图像识别技术是信息时代的一门重要的技术,其产生目的是为了让计算机代替人类去处理大量的物理信息.传统图像识别技术的过程分为信息的获取.预处理.特征抽取和选择.分类器设计和分类决策.本文也是从这四点出发进 ...
- Python生成30万条Excel 测试数据
使用Python生成30万条Excel 测试数据 from openpyxl import Workbook from concurrent.futures import ThreadPoolExec ...
- 为什么创建 Redis 集群时会自动错开主从节点?
哈喽大家好,我是咸鱼 在<一台服务器上部署 Redis 伪集群>这篇文章中,咸鱼在创建 Redis 集群时并没有明确指定哪个 Redis 实例将担任 master,哪个将担任 slave ...
- iframe子窗口调用父窗口方法
//一个iframe页面调用另一个iframe页面的方法self.parent.frames["sort_bottom"].mapp($("#id").val( ...
- 【krpano】KRPano打开黑屏: FATAL ERROR
在KRPano开发过程中,初学者打开项目经常遇到如下的问题: FATAL ERROR:tour.xml – loading failed! (0) 或者是: ERROR:Local usage wit ...
- 「luogu - P4126」「ahoi 2009」最小割
link. 也许题不错,反正有点降智- 先给结论,在 \[V_N=V \\ E_N=E \\ c(x,y)=w(x,y) \] 的流网络中: 可行边:在增广完的 induced subgraph 中, ...