http://codeforces.com/contest/382/problem/C

题意:给你n个数,然后让你添加一个数使得n+1个数能形成这样的规律,a[1]-a[0]=a[2]-a[1]=a[3]-a[2].....,问这样的数有多少个?输出出来。

 #include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
#define maxn 100001
using namespace std; int n;
int a[maxn];
int b[maxn]; int main()
{
while(scanf("%d",&n)!=EOF)
{
map<int,int>q;
int cnt=;
for(int i=; i<n; i++)
{
scanf("%d",&a[i]);
}
sort(a,a+n);
if(n==)
{
printf("-1\n");
continue;
}
if(n==)
{
if((a[]+a[])%==)
{
int m=(a[]+a[])/-a[];
if((a[]+a[])/==a[])
{
printf("1\n");
printf("%d\n",a[]);
continue;
}
printf("%d\n",);
printf("%d %d %d\n",a[]-(a[]-a[]),a[]+m,a[]+m*);
}
else
{
printf("%d\n",);
int m=a[]-a[];
printf("%d %d\n",a[]-m,a[]+m);
}
continue;
}
if(n==)
{
int m1=a[]-a[];
int m2=a[]-a[];
if(m1>m2)
{
if(m1==m2*)
{
printf("%d\n",);
printf("%d\n",a[]+m2);
}
else
{
printf("0\n");
}
}
else if(m1<m2)
{
if(m2==m1*)
{
printf("%d\n",);
printf("%d\n",a[]+m1);
}
else
{
printf("0\n");
}
}
else if(m1==m2)
{
if(a[]==a[])
{
printf("1\n");
printf("%d\n",a[]);
continue;
}
printf("2\n");
printf("%d %d\n",a[]-m1,a[n-]+m1);
}
continue;
}
int k;
int max1=;
bool flag1=true;
for(int i=; i<n; i++)
{
int m=a[i]-a[i-];
if(m==)
{
flag1=false;
}
if(q[m]==)
{
q[m]=;
}
else
q[m]++;
if(q[m]>max1)
{
max1=q[m];
k=m;
}
}
if(!flag1)
{
if(k!=)
{
printf("0\n");
continue;
}
}
if(k==)
{
bool flag=true;
for(int i=; i<n; i++)
{
if(a[i]-a[i-]!=k)
{
flag=false;
printf("0\n");
break;
}
}
if(flag==true)
{
printf("1\n");
printf("%d\n",a[]);
}
}
else
{
int f=;
for(int i=; i<n; i++)
{
if(a[i]-a[i-]!=k)
{
if(f==)
{
f=;
printf("0\n");
break;
}
else if(f==)
{
f=;
if((a[i]+a[i-])%!=)
{
printf("0\n");
f=;
break;
}
else
{
if((a[i]+a[i-])/==a[i-]+k)
b[cnt++]=(a[i]+a[i-])/;
else
{
f=;
printf("0\n");
break;
}
}
}
}
}
if(f==)
{
b[cnt++]=a[]-k;
b[cnt++]=a[n-]+k;
}
if(f==) continue;
sort(b,b+cnt);
printf("%d\n",cnt);
for(int i=; i<cnt; i++)
{
if(i==)
printf("%d",b[i]);
else printf(" %d",b[i]);
}
printf("\n");
}
}
}

cf C. Arithmetic Progression的更多相关文章

  1. CF 1114 E. Arithmetic Progression

    E. Arithmetic Progression 链接 题意: 交互题. 有一个等差序列,现已打乱顺序,最多询问60次来确定首项和公差.每次可以询问是否有严格大于x的数,和查看一个位置的数. 分析: ...

  2. POJ3495 Bitwise XOR of Arithmetic Progression

    Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 772   Accepted: 175 Description Write ...

  3. CF刷题-Codeforces Round #481-D. Almost Arithmetic Progression

    题目链接:https://codeforces.com/contest/978/problem/D 题解: 题目的大意就是:这组序列能否组成等差数列?一旦构成等差数列,等差数列的公差必定确定,而且,对 ...

  4. Dirichlet's Theorem on Arithmetic Progression

    poj3006 Dirichlet's Theorem on Arithmetic Progressions 很显然这是一题有关于素数的题目. 注意数据的范围,爆搜超时无误. 这里要用到筛选法求素数. ...

  5. CF1114E Arithmetic Progression(交互题,二分,随机算法)

    既然是在CF上AC的第一道交互题,而且正是这场比赛让我升紫了,所以十分值得纪念. 题目链接:CF原网 题目大意:交互题. 有一个长度为 $n$ 的序列 $a$,保证它从小到大排序后是个等差数列.你不知 ...

  6. Find Missing Term in Arithmetic Progression 等差数列缺失项

    查找等差数列中的缺失项. e.g.Input: arr[] = {2, 4, 8, 10, 12, 14} Output: 6 Input: arr[] = {1, 6, 11, 16, 21, 31 ...

  7. BestCoder22 1002.NPY and arithmetic progression(hdu 5143) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5143 题目意思:给出 1, 2, 3, 4 的数量,分别为a1, a2, a3, a4,问是否在每个数 ...

  8. codeforces C. Arithmetic Progression 解题报告

    题目链接:http://codeforces.com/problemset/problem/382/C 题目意思:给定一个序列,问是否可以通过只插入一个数来使得整个序列成为等差数列,求出总共有多少可能 ...

  9. CF 567C Geometric Progression

    题目大意:输入两个整数 n 和 k ,接下来输入n个整数组成的序列.求该序列中三个数 满足条件的子串个数(要求字串由三个整数a,b,c组成,其中 c = k * b = k * k * a). 思路: ...

随机推荐

  1. poj 2240 Arbitrage (Floyd)

    链接:poj 2240 题意:首先给出N中货币,然后给出了这N种货币之间的兑换的兑换率. 如 USDollar 0.5 BritishPound 表示 :1 USDollar兑换成0.5 Britis ...

  2. 计算机体系结构-内存调优IPC OOMK

    man ipc [root@server1 proc]# man ipcIPC(2)                     Linux Programmer’s Manual             ...

  3. Five ways to maximize Java NIO and NIO.2--reference

    Java NIO -- the New Input/Output API package-- was introduced with J2SE 1.4 in 2002. Java NIO's purp ...

  4. 彻底删除mysql的方法(有隐藏文件)

    1.建议使用360进行卸载,可以彻底卸载软件 2.360会提醒删除注册表 3.这个隐藏文件要删除掉 在 C:\Documents and Settings\ 路径下搜索 MySQL 文件夹(默认隐藏的 ...

  5. ASP.net MVC 多语言处理

    MVC多语言处理主要分两部分,一部分是Razor视图中的文字标签内容切换, 另一部分是javascript文件中的文标签内容切换.  这里分这两部分来说. View视图中的比较好做, 思路是使用资源文 ...

  6. node 搭建开发框架express

    参考地址: http://www.itnose.net/detail/6095003.html 开发环境 E:\project> node -v v0.10.30 E:\project> ...

  7. Gprinter Android SDK V2.1.4 使用说明

    佳博打印机Android的SDK开发包,已更新到Gprinter Android SDK V2.1.4. IOS的SDK开发包更新为GprinterSDKandDemoforIOS_v1.0.8. 根 ...

  8. sid超过8个字符处理步骤

    服务端配置如下: [oracle@p3 admin]$ cat listener.ora # listener.ora Network Configuration File: /home/oracle ...

  9. npm的镜像替换成淘宝

    1.得到原本的镜像地址 npm get registry > https://registry.npmjs.org/ 设成淘宝的 npm config set registry http://r ...

  10. POJ 3468.A Simple Problem with Integers 解题报告

    用树状数组和线段树会比较简单,这里用这道题来学习Splay. 第一次写,代码比较丑 /* 初始化添加一个key值足够大的结点 保证每个需要的结点都有后继 */ #include <iostrea ...