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 ...
随机推荐
- 基础(三):yum(RedHat系列)和apt-get(Debian系列 )用法及区别
文章转载来自:http://blog.csdn.net/chengly0129/article/details/70169760 一般来说著名的linux系统基本上分两大类:1.RedHat系列:Re ...
- docker仓库管理(9)
使用公共 Registry Docker Hub 是 Docker 公司维护的公共 Registry.用户可以将自己的镜像保存到 Docker Hub 免费的 repository 中.如果不希望别人 ...
- Python100天打卡-Day10
实现动画效果要实现动画效果,本身的原理也非常简单,就是将不连续的图片连续的播放,只要每秒钟达到了一定的帧数,那么就可以做出比较流畅的动画效果.import pygame def main(): # 初 ...
- (15)centos7 系统服务
centos7 服务启动脚本在 /usr/lib/systemd目录下 1.服务基本操作指令 systemclt [command] [unit] #其中command包括: #start 立即启动 ...
- PHP简单读取XML
DOM document object model,文档对象模型,就是树形结构 节点的分类 元素节点 属性节点 值节点 注释节点 根节点(document才是根节点) 生成XML文档 xml的根节点为 ...
- ICPC Asia Nanning 2017 I. Rake It In (DFS+贪心 或 对抗搜索+Alpha-Beta剪枝)
题目链接:Rake It In 比赛链接:ICPC Asia Nanning 2017 Description The designers have come up with a new simple ...
- Comet OJ - Contest #4 B题 奇偶性
题目链接:https://www.cometoj.com/contest/39/problem/B?problem_id=1577 题意:给你一个数列,求L 到 R 区间内 所有数列 (ƒn mod ...
- 【gcc】更新下载编译gcc遇到的各种问题
帮学长的oj升级gcc版本.遇到了贼多问题.. [悲惨的开始] 安装gcc版本推荐ustc的mirror的下载,超快der... https://mirrors.ustc.edu.cn/gnu/gcc ...
- 枚举加countdownLatch的使用
package com.cxy.juc; import java.util.concurrent.CountDownLatch; public class CountDownlatchDemo { p ...
- idea一直在copying resources或者一直在build,卡住不动,问题已解决
IDE在启动项目的过程中,一直copying,或者是build一直卡住,需要在modules中配置下,把target文件夹移出resource folder 同时,在此之前,我还屏蔽了项目中pom.x ...