Codeforces 1154B Make Them Equal
题目链接:http://codeforces.com/problemset/problem/1154/B


题意:给定数组,可以给任意的的元素加上D 或者 减去D,如果能 使数组元素都相等,输出最小的D,不能输出-1。
思路:若要相等,唯有种类数小于3的才可以。
AC代码:
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
int a[];
int x,y,z;
set<int> st;
cin >> n;
for(int i = ;i < n;i++) cin >> a[i],st.insert(a[i]);
if(st.size() == ) cout << "" << endl;
else if(st.size() == )
{
int x = *st.rbegin() - *st.begin();
if(x % ) cout << x;
else cout << x / ;
}
else if(st.size()==&& (x=*st.begin(),y=*++(st.begin()),z=*st.rbegin(),z-y==y-x) )
cout<<z-y;
else cout<<-; return ;
}
Codeforces 1154B Make Them Equal的更多相关文章
- codeforces 622C C. Not Equal on a Segment
C. Not Equal on a Segment time limit per test 1 second memory limit per test 256 megabytes input sta ...
- Codeforces 1065C Make It Equal (差分+贪心)
题意:n个塔,第i个塔由$h_i$个cube组成,每次可以切去某高度h以上的最多k个cube,问你最少切多少次,可以让所有塔高度相等 k>=n, n<=2e5 思路:差分统计每个高度i有的 ...
- CF #552 div3
A - Restoring Three Numbers CodeForces - 1154A Polycarp has guessed three positive integers aa, bb a ...
- Educational Codeforces Round 7 C. Not Equal on a Segment 并查集
C. Not Equal on a Segment 题目连接: http://www.codeforces.com/contest/622/problem/C Description You are ...
- Educational Codeforces Round 2 B. Queries about less or equal elements 水题
B. Queries about less or equal elements Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforc ...
- Codeforces gym101612 E.Equal Numbers(贪心)
传送:http://codeforces.com/gym/101612 题意:给出一个大小为n的序列a[i],每次选其中一个数乘以一个正整数,问进行k步操作后最少剩下多少种数字,输出0≤k≤n,所有的 ...
- CodeForces - 600B Queries about less or equal elements (二分查找 利用stl)
传送门: http://codeforces.com/problemset/problem/600/B Queries about less or equal elements time limit ...
- CodeForces A. Many Equal Substrings
http://codeforces.com/contest/1029/problem/A You are given a string tt consisting of nn lowercase La ...
- Codeforces 600B Queries about less or equal elements(二分查找)
Description You are given two arrays of integers a and b. For each element of the second array bj yo ...
随机推荐
- luoguP3806 【模板】点分治1 [点分治]
题目背景 感谢hzwer的点分治互测. 题目描述 给定一棵有n个点的树 询问树上距离为k的点对是否存在. 输入输出格式 输入格式: n,m 接下来n-1条边a,b,c描述a到b有一条长度为c的路径 接 ...
- 攻防世界 MISC篇
Excaliflag 一张图片,winhex打开没什么发现,分值不高,应该属于常见的图片隐写题目.如果对于图片的格式有详细的了解,应该很容易就能够知道了属于最低有效位(LSB)隐写,下面是通过phot ...
- webpack 添加eslint代码审查
1). 添加包 npm install eslint --save-dev npm install eslint-loader --save-dev npm install eslint-plugin ...
- leyou_04_使用vue.js搭建页面—使用ajax完成品牌的查询
1.使用vue.js搭建页面 1.1使用的模板插件Vuetify 中文UI组件官网:https://vuetifyjs.com/zh-Hans/getting-started/quick-start ...
- JZOI1134 迷宫(maze)
#include <bits/stdc++.h> #define ll long long #define INF 2147483647 #define mem_INF 213906214 ...
- linux 查看cpu,memory
https://www.cnblogs.com/ctypyb2002/p/9792951.html
- 3、第一个Appium测试
运行脚本前环境准备: 1.IDE,推荐使用IJ 2.安装jdk环境,推荐>1.8 3.准备一台真机或者模拟器 4.SDK 5.maven环境 项目目录: CalculatorTest.java文 ...
- 剑指offer第二版面试题6:重建二叉树(JAVA版)
题目:输入某二叉树的前序遍历和中序遍历的结果,请重新构造出该二叉树.假设输入的前序遍历和中序遍历的结果中不包含重复的数字.例如输入的前序遍历序列为{1,2,4,7,3,5,6,8}和中序遍历为{4,7 ...
- Day 21 python :面向对象 类的相关内置函数 /单例模式 /描述符
1.isinstance(obj,cls) 检查obj是否是类cls的对象: 备注:用isinstance 的时候,产生实例后,会显示实例既是父类的实例,也是子类的实例 class Mom: gend ...
- Haproxy负载均衡/动静分离(haproxy各选项详细解释)
在前端领域做负载均衡,动静分离的程序有很多,比较常用的是nginx和Haproxy,今天就说一下 Haproxy在这两方面的表现,文章参考很多网文写成,再加上自己的实验成果,文中所有解释都经过实际环境 ...