Codeforces 714B. Filya and Homework
题目链接:http://codeforces.com/problemset/problem/714/B
题意:
给你一个含有 n 个数的数组, 问你是否存在一个 x, 使得这个数组中的某些数加上 x, 某些数减去 x 后所有数都相等.
思路:
如果这个数组里面不相等的数大于 3 个那么 x 就不可能存在. 否则如果这个数组里仅有三个数不一样且设为 a, b, c(a < b < c), 则还必须满足 b - a == c - b. 使得所有等于 a 的数加上 b - a 变为 b, 所有等于 c 的数减去 c - b 也变为 b, 则可以让所有数相等. 如果这个数组里面仅有两个数不一样且设为 a, b, 那么给所有为 a 的数加 (b - a) 或者给所有值为 b 的数减去(b - a) 那么这个数组里所有数也会相等. 如果这个数组里的数全部相等, 则不用变化就好, 上述三种情况满足其一就可以满足题意.
代码:
#include <bits/stdc++.h> using namespace std;
typedef long long LL;
const int MAXN = ;
int arv[MAXN + ]; int main() {
ios_base::sync_with_stdio(); cin.tie();
int n; cin >> n;
for(int i = ; i < n; i++) cin >> arv[i];
sort(arv, arv + n);
int jud[MAXN + ], len = ;
jud[len++] = arv[];
for(int i = ; i < n; i++) if(arv[i] != arv[i - ]) jud[len++] = arv[i];
if(len == || len == || (len == && jud[] + jud[] == jud[] * ) ) cout << "YES" << endl;
else cout << "NO" << endl;
return ;
}
Codeforces 714B. Filya and Homework的更多相关文章
- Codeforces Round #371 (Div. 2) B. Filya and Homework 水题
B. Filya and Homework 题目连接: http://codeforces.com/contest/714/problem/B Description Today, hedgehog ...
- 【31.95%】【CF 714B】Filya and Homework
time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...
- Codeforces Round #371 (Div. 2)B. Filya and Homework
题目链接:http://codeforces.com/problemset/problem/714/B 题目大意: 第一行输入一个n,第二行输入n个数,求是否能找出一个数x,使得n个数中的部分数加上x ...
- B. Filya and Homework
http://codeforces.com/contest/714/problem/B 给定一个序列,对于每一个元素,只能 + 或者 - 一个数val.这个数一旦选定,就不能改. 问能否变成全部数字都 ...
- 【CodeForces 717C】Potions Homework
BUPT 2017 summer training (for 16) #1G 题意 每个人有一个懒惰值,每个任务有个难度,一开始每个人的任务和懒惰值都为\(a_i\),完成任务时间是懒惰值乘以难度,现 ...
- 【39.68%】【CF 714 C】Filya and Homework
time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...
- Codeforces水题集合[14/未完待续]
Codeforces Round #371 (Div. 2) A. Meeting of Old Friends |B. Filya and Homework A. Meeting of Old Fr ...
- Codeforces Round #371 (Div. 2)(set\unique)
B. Filya and Homework time limit per test 1 second memory limit per test 256 megabytes input standar ...
- Codeforces Round #371 (Div. 2) A ,B , C 水,水,trie树
A. Meeting of Old Friends time limit per test 1 second memory limit per test 256 megabytes input sta ...
随机推荐
- Git新手上路,让你快速掌握Git的基本使用
github是一个基于git的代码托管平台,付费用户可以建私人仓库,我们一般的免费用户只能使用公共仓库,也就是代码要公开.这对于一般人来说公共仓库就已经足够了. 1.注册账户以及创建仓库 要想 ...
- 51nod 1873 高精度计算
JAVA BigDecimal import java.util.*; import java.math.*; public class Main { public static void main( ...
- Codeforces 713C Sonya and Problem Wihtout a Legend DP
C. Sonya and Problem Wihtout a Legend time limit per test 5 seconds memory limit per test 256 megaby ...
- 「模板」 树链剖分 HLD
「模板」 树链剖分 HLD 不懂OOP的OIer乱用OOP出人命了. 谨此纪念人生第一次类套类. 以及第一次OI相关代码打过200行. #include <algorithm> #incl ...
- Idea Ant 打开发包
简介: http://ju.outofmemory.cn/entry/19239 语法: https://wenku.baidu.com/view/a0e00315866fb84ae45c8d9d.h ...
- 【BZOJ4514】【SDOI2016】数字配对 [费用流]
数字配对 Time Limit: 10 Sec Memory Limit: 128 MB[Submit][Status][Discuss] Description 有 n 种数字,第 i 种数字是 ...
- 【HDU】2222 Keywords Search
[算法]AC自动机 [题解]本题注意题意是多少关键字能匹配而不是能匹配多少次,以及可能有重复单词. 询问时AC自动机与KMP最大的区别是因为建立了trie,所以对于目标串T与自动机串是否匹配只需要直接 ...
- Little Mathematics Knowledge 数学小常识
The sum of arithmetic sequence The sum of geometric sequence A special formula : n·n! = (n+1)! - n! ...
- pythonTensorFlow实现yolov3训练自己的目标检测探测自定义数据集
1.数据集准备,使用label标注好自己的数据集. https://github.com/tzutalin/labelImg 打开连接直接下载数据标注工具, 2.具体的大师代码见下链接 https:/ ...
- javascript 变量类型判断
一.typeof 操作符 对于Function, String, Number ,Undefined 等几种类型的对象来说,他完全可以胜任,但是为Array时 "); typeof arr ...