题目链接: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的更多相关文章

  1. 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 ...

  2. Codeforces 1065C Make It Equal (差分+贪心)

    题意:n个塔,第i个塔由$h_i$个cube组成,每次可以切去某高度h以上的最多k个cube,问你最少切多少次,可以让所有塔高度相等 k>=n, n<=2e5 思路:差分统计每个高度i有的 ...

  3. CF #552 div3

    A - Restoring Three Numbers CodeForces - 1154A Polycarp has guessed three positive integers aa, bb a ...

  4. 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 ...

  5. 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 ...

  6. Codeforces gym101612 E.Equal Numbers(贪心)

    传送:http://codeforces.com/gym/101612 题意:给出一个大小为n的序列a[i],每次选其中一个数乘以一个正整数,问进行k步操作后最少剩下多少种数字,输出0≤k≤n,所有的 ...

  7. CodeForces - 600B Queries about less or equal elements (二分查找 利用stl)

    传送门: http://codeforces.com/problemset/problem/600/B Queries about less or equal elements time limit ...

  8. CodeForces A. Many Equal Substrings

    http://codeforces.com/contest/1029/problem/A You are given a string tt consisting of nn lowercase La ...

  9. 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 ...

随机推荐

  1. tarjan求强连通+缩点——cf1248E

    这题好像是DEF里最水的,, /* 建图:如果a认识b,那么从a->b连一条边,将点分成两个集合A,B,没有从A->B的边 求出强连通分量,再造一张新图,新图中任取一个的出度为0的点作为集 ...

  2. STM32嵌入式开发学习笔记(七):串口通信(下)

    下面我们进行几个串口通信的实际应用. 实验一:发信实验,让开发板通过串口向电脑发送信息: #include <stdio.h> #include <stm32f10x.h> # ...

  3. 动态栈-------C语言

    使用带头结点的单链表实现 主要使用链表中的头插来实现栈的先进后出的特点 /***************************************************** Author:Si ...

  4. TI低功耗蓝牙(BLE)介绍【转】

    转自:http://blog.csdn.net/ooakk/article/details/7302425 TI低功耗蓝牙(BLE)介绍 本文档翻译和修改自参考资料:CC2540Bluetooth L ...

  5. java中的javap命令(工作中补充的知识)

    背景: 上周针对某信得压力测试demo进行场景复现,但是只提供了class文件,只能通过反编译的软件进行查看,在复现的过程中报错某某某行,这里我以xx行代替,因为是class文件,所以并不能确定具体到 ...

  6. 17、通过maven生成测试报告

    目录如下: 通过Maven 生成报告 进入testngTest根目录,运行mvn test 命令 进入 testngTest\target\surefire-reports 路径查看测试报告

  7. Netty 源码学习——EventLoop

    Netty 源码学习--EventLoop 在前面 Netty 源码学习--客户端流程分析中我们已经知道了一个 EventLoop 大概的流程,这一章我们来详细的看一看. NioEventLoopGr ...

  8. docker hub的使用

    讲自己的镜像推送到docker hub 一.将自己的image上标签 docker tag ubuntu:18.04 username/ubuntu:18.04 二.登陆自己的docker hub d ...

  9. jquery插件小集合

    一.滑动轮播插件Swiper Swiper官网http://www.swiper.com.cn/, 这款插件移动端,pc端均试用 二.jquery-tmpl----让你从拼接字符串中解放出来 官方下载 ...

  10. 48-Ubuntu-系统信息-3-查看进程命令

    序号 命令 作用 01 ps aux  process status查看进程的详细状况 02 top 动态显示运行中的进程并且排序 03 kill [-9] 进程代号 终止指定代号的进程,-9表示强行 ...