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的路径 接 ...
- 前缀和+排序——cf1043E
先不考虑第二个条件 要求i和所有其他人的分数和最小,选择x还是y,可以推出一个公式,即差xi-yi小的j都选y,反之都选x 那么按照xi-yi排序即可 然后再考虑第二个条件,做减法就行 /* xi+y ...
- elementUi-复选框,使用v-for循环出来的复选框,默认多个值为勾选状态
1. 使用 v-model="BottomSelectFor[index].tick" 绑定要默认勾选的状态 2.在数组中定义 tick:true,没有的字段默认为false 3. ...
- noip1998 提高组t3 挖地雷
题目背景 NOIp1996提高组第三题 题目描述 在一个地图上有N个地窖(N<=20),每个地窖中埋有一定数量的地雷.同时,给出地窖之间的连接路径.当地窖及其连接的数据给出之后,某人可以从任一处 ...
- idea 中使用dataBase插件
最近一段时间重新开始学习Java 使用IntelliJ 发现有个链接数据库插件挺好用的,并且反应速度还挺快的记录下. 点击步骤:View → Tool Windows → data 进行数据库链接 发 ...
- idea整合springboot,访问templates下html资源问题
1.pom.xml文件中要引入themyleaf 2.在application.properties文件中加入 #拼接html前后缀spring.resources.static-locations= ...
- JAVA调用R脚本
0 前言R是一种非常方便易用的绘图.统计分析.ML算法设计方面的脚本语言.实际中有这样一种场景:算法工程师用R搭建了机器学习算法模型,想用于javaweb之中但是又不想重新用java写一遍算法模型,那 ...
- ajax url地址
当前网址 http://localhost:8080/exam_paper/402881ec5c3924ec015c394ee4210000/set_questions ajax请求url var u ...
- C++变长参数
如果C++的变长参数经过了多轮的调用,就可能失去作用 间接引址,但是只能引用到第一个变长参数. va_list marker; va_start(marker, format); s_logger ...
- HDU 5119 Happy Matt Friends (背包DP + 滚动数组)
题目链接:HDU 5119 Problem Description Matt has N friends. They are playing a game together. Each of Matt ...