https://codeforces.com/contest/1154/problem/B

题意:给定一个数组,现在有一个操作:对于数组的某个元素,你可以加或者减D(仅一次)。任务是将数组的所有值变成一样的。输出D的值,不存在输出-1。

题解:等差数列+思维

1、特判n==1的时候;

2、特判元素为2个,而且公差为偶数的时候

/*
*@Author:   STZG
*@Language: C++
*/
#include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<deque>
#include<stack>
#include<cmath>
#include<list>
#include<map>
#include<set>
//#define DEBUG
#define RI register int
#define endl "\n"
using namespace std;
typedef long long ll;
//typedef __int128 lll;
const int N=100000+10;
const int M=100000+10;
const int MOD=1e9+7;
const double PI = acos(-1.0);
const double EXP = 1E-8;
const int INF = 0x3f3f3f3f;
int t,n,m,k,p,l,r,u,v;
int ans,cnt,flag,temp,sum;
int a[N],b[N];
char str;
struct node{};
int main()
{
#ifdef DEBUGfreopen("input.in", "r", stdin);//freopen("output.out", "w", stdout);
#endif//ios::sync_with_stdio(false);//cin.tie(0);//cout.tie(0);//scanf("%d",&t);//while(t--){scanf("%d",&n);for(int i=1;i<=n;i++)scanf("%d",&a[i]);sort(a+1,a+n+1);b[++cnt]=a[1];for(int i=2;i<=n;i++){if(a[i-1]!=a[i])b[++cnt]=a[i];}if(cnt==1){cout<<0<<endl;return 0;}int d=(b[2]-b[1]);for(int i=3;i<=cnt;i++){if(b[i]-b[i-1]!=d){cout<<-1<<endl;return 0;}}if(cnt==2&&d%2==0){d/=2;}cout<<d<<endl;//}#ifdef DEBUGprintf("Time cost : %lf s\n",(double)clock()/CLOCKS_PER_SEC);
#endif//cout << "Hello world!" << endl;return 0;
}

Make Them Equal相关推荐

  1. java equal hashcode_Java(二)equal 和 hashcode使用

    一.hashCode()和equals()是什么? hashCode()方法和equals()方法的作用其实一样,在Java里都是用来对比两个对象是否相等一致. Equal 没有重写的equal 使用 ...

  2. 讨论JDK的File.equal()

    我们一般比较两个文件中的对象是相同的文件,通常使用java.io.File.equal().这里,equal()是不是文件内容的比较结果为.象是否指向同一个文件. File的equal()方法.实际上 ...

  3. RuntimeError: each element in list of batch should be of equal size

    RuntimeError: each element in list of batch should be of equal size 示例代码: import os import re from t ...

  4. 语义分割--Not All Pixels Are Equal:Difficulty-Aware Semantic Segmentation via Deep Layer Cascade

    Not All Pixels Are Equal: Difficulty-Aware Semantic Segmentation via Deep Layer Cascade CVPR2017 本文针 ...

  5. logic:equal 标签的使用(转)

    <logic:equal name="music" property="distrubute" value="true">    ...

  6. 记录由Equal基础知识引起的内存泄露

    在最近的公司框架开发中,利用了网上某大牛的反射缓存库作为辅助.在测试的时候发现出现了巨大的内存泄露,在频繁的操作后,内存不断的产生巨大的开销,10多分钟就占有了5,6m的内存.解决问题的时,公司不能上 ...

  7. 无法解决 equal to 操作中 SQL_Latin1_General_CP1_CI_AS 和 Chinese_PRC_CI_AS 之间的排序规则冲突。...

    一个旧有系统需要从另一个新系统获取数据.由于两个系统数据库的的排序规规则不同.在存储过程中SELECT数据时,引发了"无法解决 equal to 操作中 "SQL_Latin1_G ...

  8. LeetCode Minimum Moves to Equal Array Elements II

    原题链接在这里:https://leetcode.com/problems/minimum-moves-to-equal-array-elements-ii/ 题目: Given a non-empt ...

  9. C#中的==、Equal、ReferenceEqual(转载)

    1. ReferenceEquals, == , Equals  Equals , == , ReferenceEquals都可以用于判断两个对象的个体是不是相等. a) ReferenceEqual ...

  10. 【Vegas原创】“無法解析 equal to 動作的定序衝突”错误的处理

    错误:無法解析 equal to 動作的定序衝突. COLLATE Chinese_Taiwan_Stroke_CI_AS 用法: select @EMP_ID=emp_id from am_empl ...

最新文章

  1. 微信小程序的数字有部分会自动加粗的解决方法
  2. 一句话介绍区块链是什么
  3. yum 转mysql_centos下彻底删除MYSQL 和重新安装MYSQL(转)
  4. 浅析 Linux 初始化系统(系统服务管理和控制程序/Init System) -- systemd
  5. linux中的信号1——信号概述
  6. C#将一个excel工作表根据指定范围拆分为多个excel文件
  7. 微软正在开发基于 Rust 的安全编程语言
  8. c语言打开文件出现分段故障,C文件I / O中的分段故障11(Segmentation Fault 11 in C File I/O)...
  9. python电脑下载安装-python
  10. Win10系统msvcr120.dll丢失解决
  11. 一个中产阶级丈夫给坚持买房妻子的一封信
  12. 子类发送消息_RocketMQ生产消息源码解析
  13. 8代cpu能装linux 系统吗,Intel支持八九代酷睿的B365芯片组将登场亮相
  14. matlab与螺旋桨,基于Matlab的船用螺旋桨计算机实时仿真及GUI设计
  15. java调试查看调用堆栈_关于调试:如何阅读和理解java堆栈跟踪?
  16. Python3 OpenCV 视频转字符动画
  17. debugger心得
  18. Dockerfile中ADD文件用法
  19. java环境变量配置_Java环境变量配置终极版
  20. maven html项目自动版本控制(时间戳) com.google.code.maven-replacer-plugin插件 前端代码自动添加版本号

热门文章

  1. 苹果手机夜间模式怎么设置_微信夜间模式终于来了,苹果和安卓都适用!
  2. oracle表对比同步,Oracle表双向同步问题
  3. 动态让控件超出屏幕_JAVA浏览器控件JxBrowser v7.5上线!更轻松处理Dynamic Favicons...
  4. php 输出excepion内容,带有消息“无法关闭zip文件php://输出”的PHPExcel_Writer_Exception...
  5. 微信红包随机数字_微信红包的随机算法
  6. centos7开发java体验_centos7之Java开发环境构建
  7. 分布式内存数据库--Redis事务
  8. android SQLite查询并显示用户输入的选择信息
  9. 四十、Java中字节流和字符流介绍和区别
  10. 十一、Powerbi函数篇