【链接】 我是链接,点我呀:)

【题意】

让你在n个数字中再加入一个数字
使得这n+1个数字排序之后
相邻两个数字的差都相同

【题解】

注意相邻为0的情况 这种情况 只有全都相同才行 只有一种情况
然后就是样例里的a[i]-a[i-1]只有两种数字
然后较小的a[i]-a[i-1]有n-2个,较大的a[i]-a[i-1]有1个,然后较大的是较小的两倍
注意这些细节就好了

【代码】

import java.io.*;
import java.util.*; public class Main { static InputReader in;
static PrintWriter out; public static void main(String[] args) throws IOException{
//InputStream ins = new FileInputStream("E:\\rush.txt");
InputStream ins = System.in;
in = new InputReader(ins);
out = new PrintWriter(System.out);
//code start from here
new Task().solve(in, out);
out.close();
} static int N = (int)1e5;
static class Task{ int n;
int a[] = new int[N+10];
HashMap<Integer,Integer> dic = new HashMap<>(); public void solve(InputReader in,PrintWriter out) {
n = in.nextInt();
for (int i = 1;i <= n;i++) a[i] = in.nextInt();
Arrays.sort(a, 1,n+1);
if (n==1) {
out.println(-1);
}else if (n==2) {
if (a[1]==a[2]) {
out.println(1);
out.println(a[1]);
}else {
if ( (a[1]+a[2])%2==0) {
int temp = a[2]-a[1];
out.println(3);
out.print((a[1]-temp)+" "+((a[1]+a[2])/2)+" "+(a[2]+temp) );
}else {
int temp = a[2]-a[1];
out.println(2);
out.println((a[1]-temp)+" "+(a[2]+temp));
}
}
}else {
int temp = a[2]-a[1];
boolean ok = true;
for (int i = 3;i <= n;i++) {
if (a[i]-a[i-1]!=temp) {
ok = false;
}
}
if (ok) {
if (temp==0) {
out.println(1);
out.println(a[1]);
}else {
out.println(2);
out.println((a[1]-temp)+" "+(a[n]+temp));
}
}else {
for (int i = 2;i <= n;i++) {
if (dic.containsKey(a[i]-a[i-1])) {
int x = dic.get(a[i]-a[i-1]);
dic.put(a[i]-a[i-1],x+1);
}else {
dic.put(a[i]-a[i-1], 1);
}
}
if (dic.size()>2) {
out.println(0);
}else {
Iterator it = dic.keySet().iterator();
int temp1 = (int)it.next();
int temp2 = (int)it.next();
if (temp1>temp2) {
int xx = temp1;temp1 = temp2;temp2 = xx;
}
if ( (temp2 == temp1*2) && ( (int)dic.get(temp2) )==1 ) {
out.println(1);
for (int i = 2;i <= n;i++) {
if (a[i]-a[i-1]==temp2) {
out.println(a[i-1]+temp1);
}
}
}else {
out.println(0);
}
}
}
}
}
} static class InputReader{
public BufferedReader br;
public StringTokenizer tokenizer; public InputReader(InputStream ins) {
br = new BufferedReader(new InputStreamReader(ins));
tokenizer = null;
} public String next(){
while (tokenizer==null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(br.readLine());
}catch(IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
} public int nextInt() {
return Integer.parseInt(next());
}
}
}

【Codeforces 382C】Arithmetic Progression的更多相关文章

  1. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  2. 【codeforces 604D】Moodular Arithmetic

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  3. 【51.27%】【codeforces 604A】Uncowed Forces

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  4. 【codeforces 707E】Garlands

    [题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...

  5. 【codeforces 707C】Pythagorean Triples

    [题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...

  6. 【codeforces 709D】Recover the String

    [题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...

  7. 【codeforces 709B】Checkpoints

    [题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...

  8. 【codeforces 709C】Letters Cyclic Shift

    [题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...

  9. 【Codeforces 429D】 Tricky Function

    [题目链接] http://codeforces.com/problemset/problem/429/D [算法] 令Si = A1 + A2 + ... + Ai(A的前缀和) 则g(i,j) = ...

随机推荐

  1. bzoj 4719: [Noip2016]天天爱跑步【树上差分+dfs】

    长久以来的心理阴影?但是其实非常简单-- 预处理出deep和每组st的lca,在这里我简单粗暴的拿树剖爆算了 然后考虑对于一组s t lca来说,被这组贡献的观察员x当且仅当: x在s到lca的路径上 ...

  2. [Swift通天遁地]一、超级工具-(13)使用PKHUD制作各种动态提示窗口

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  3. 公司6:JrVue重用布局

    JrVue是我们基于element重新封装的一套组件库;  为了提高开发效率, 方便对代码的统一管理和维护,  我们提供了一些统一的页面布局, 以及项目常用的中小型模块 我在master新拉一个分支J ...

  4. C - GCD LCM

    Description The GCD of two positive integers is the largest integer that divides both the integers w ...

  5. jmeter生成时间的函数

    在一个接口测试中,需要提交的请求中要带时间,在看完jmeter帮忙文档,正好总结一下 1.需求 在一个http请求中请求数据要带有时间,如下: 2.实现 突然想到jmeter自带的函数助手好像是可以实 ...

  6. SQL数据库--数据访问

    数据访问: 对应命名空间:System.Data.SqlClient; SqlConnection:连接对象 SqlCommand:命令对象 SqlDataReader:读取器对象 //造连接字符串 ...

  7. [ HDOJ 3826 ] Squarefree number

    \(\\\) \(Description\) \(T\)组数据,每次给出一个正整数 \(N\) ,判断其是否能被任意一个完全平方数整除. \(T\le 20,N\le 10^{18}\) \(\\\) ...

  8. Python中*args和**kwargs的使用

    函数定义 使用*args和**kwargs传递可变长参数: *args用作传递非命名键值可变长参数列表(比如元组) **kwargs用作传递键值可变长参数列表(比如字典) 函数入参 *args 传递一 ...

  9. nginx--提供一键安装脚本

    nginx特点 基于进程池实现的fastcgi 单一进程即可实现处理上千的连接 易于扩展的插件系统 安装篇 *下载源码 curl -O http://nginx.org/download/nginx- ...

  10. CLISTCTRL 获取点击列

    CListCtrl中的HitTest.SubItemHitTest的用法 2HitTest:得到当前鼠标位置的Item 其实关键是要有ScreenToClient这个函数的使用,我先前没有用这个函数, ...