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 ...
随机推荐
- 暴力字符串hash——cf1200E
#include<bits/stdc++.h> using namespace std; #define ll long long #define N 1000005 #define mo ...
- 转载-NX11.0二次开发新增Spreadsheet相关类的用法!
这几天搜NX对EXCAL读取写入相关的开发内容,发现唐工写了一篇关于NX11对EXCAL操作的文章.让我知道NX11新增了对EXCAL操作相关的类,以前NX里是没有的.我以前都是用OLE方式去做,没用 ...
- atlcomcli.h(1756): error C2338: CVarTypeInfo< char > cannot be compiled with /J or _CHAR_UNSIGNED fl
我拿到一个VS的工程,用VS2010 编译 时提示: atlcomcli.h(1756): error C2338: CVarTypeInfo< char > cannot be comp ...
- arttemplate 后台返回的数据格式问题
1. 2.JSON.parse() 方法用于将一个 JSON 字符串转换为对象. $("body").on("click","#analyze&quo ...
- PAT_A1096#Consecutive Factors
Source: PAT A1096 Consecutive Factors (20 分) Description: Among all the factors of a positive intege ...
- 【Java多线程系列一】Java实现线程方法
Java实现线程的两种方法 继承Thread类 实现Runnable接口 它们之间的区别如下: Java的类为单继承,但可以实现多个接口,因此Runnable可能在某些场景比Thread更适用 Thr ...
- JUC源码分析-线程池篇(二)FutureTask
JUC源码分析-线程池篇(二)FutureTask JDK5 之后提供了 Callable 和 Future 接口,通过它们就可以在任务执行完毕之后得到任务的执行结果.本文从源代码角度分析下具体的实现 ...
- 关于kettle
1.点spoon.bat无报错也不运行 可以运行一下spoonDebug.bat 查看一下spoondebug.txt日志 我遇到这个问题时 是给他分配的内存太多了 我的电脑只有2g 给果他给分了20 ...
- swagger2 注解说明 ( @ApiImplicitParams )
@Api:用在请求的类上,表示对类的说明 tags="说明该类的作用,可以在UI界面上看到的注解" value="该参数没什么意义,在UI界面上也看到,所以不需要配置&q ...
- 【JZOJ3293】【BZOJ4416】【luoguP3989】阶乘字符串
description 给定一个由前n个小写字母组成的串S. 串S是阶乘字符串当且仅当前n个小写字母的全排列(共n!种)都作为S的子序列(可以不连续)出现. 由这个定义出发,可以得到一个简单的枚举法去 ...