CodeForces 382C【模拟】
活生生打成了大模拟。。。
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int>PII;
const double eps=1e-5;
const double pi=acos(-1.0);
//const int mod=1e9+7;
const int INF=0x3f3f3f3f;
//http://codeforces.com/contest/382/submission/22599025 const int N=1e5+10;
int a[N];
int ans[N],num;
int n; void shuchu()
{
sort(ans,ans+num);
int e=unique(ans,ans+num)-ans;
printf("%d\n",e);
for(int i=0; i<e; i++)
printf("%d ",ans[i]);
} map<int,int>mp;
int mp_num; int main()
{
scanf("%d",&n);
for(int i=1; i<=n; i++)
scanf("%d",&a[i]); sort(a+1,a+1+n); if(n==1)
{
puts("-1");
return 0;
}
if(n==2)
{
int d=a[n]-a[n-1];
if(d%2==1)
{
num=0;
ans[num++]=a[n-1]-d;
ans[num++]=a[n]+d;
shuchu();
}
else
{
num=0;
ans[num++]=a[n-1]-d;
ans[num++]=a[n]-d/2;
ans[num++]=a[n]+d;
shuchu();
}
return 0;
}
//3 4 4 5
//1 2 3
//1 2 4
int d1,temp,d2,num1,num2;
int dx1,dx2;
num2=num1=0;
d1=a[2]-a[1];
dx1=2;
num1++;
mp_num=1;
mp[d1]=1;
for(int i=3; i<=n; i++)
{
temp=a[i]-a[i-1];
if(!mp[temp])
{
mp[temp]=1;
mp_num++;
}
if(temp!=d1)
{
num2++;
dx2=i;
d2=temp;
}
else
num1++;
}
if(mp_num>=3)
{
puts("0");
return 0;
}
if(!num2)
{
num=0;
ans[num++]=a[1]-d1;
ans[num++]=a[n]+d1;
shuchu();
}
else
{
if(num1==1&&num2==1)
{
int res=a[dx2]-d1;
if(res*2==(a[dx2]+a[dx2-1]))
{
puts("1");
printf("%d\n",res);
return 0;
}
res=a[dx1]-d2;
if(res*2==(a[dx1]+a[dx1-1]))
{
puts("1");
printf("%d\n",a[dx1]-d2);
return 0;
}
puts("0");
}
else if(num2==1)
{
int res=a[dx2]-d1;
if(res*2==(a[dx2]+a[dx2-1]))
{
puts("1");
printf("%d\n",res);
}
else
puts("0");
}
else if(num1==1)
{
int res=a[dx1]-d2;
if(res*2==(a[dx1]+a[dx1-1]))
{
puts("1");
printf("%d\n",a[dx1]-d2);
}
else
puts("0");
}
else
puts("0");
}
return 0;
}
CodeForces 382C【模拟】的更多相关文章
- CodeForces - 427B (模拟题)
Prison Transfer Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u Sub ...
- CodeForces - 404B(模拟题)
Marathon Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u Submit Sta ...
- Codeforces 709B 模拟
B. Checkpoints time limit per test:1 second memory limit per test:256 megabytes input:standard input ...
- CodeForces - 404A(模拟题)
Valera and X Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u Submit ...
- Codeforces 390A( 模拟题)
Inna and Alarm Clock Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64 ...
- Codeforces 452D [模拟][贪心]
题意: 给你k件衣服处理,告诉你洗衣机烘干机折叠机的数量,和它们处理一件衣服的时间,要求一件衣服在洗完之后必须立刻烘干,烘干之后必须立刻折叠,问所需的最小时间. 思路: 1.按照时间模拟 2.若洗完的 ...
- CodeForces - 796B 模拟
思路:模拟移动即可,如果球落入洞中停止移动.注意:有可能第一个位置就是洞!! AC代码 #include <cstdio> #include <cmath> #include ...
- CodeForces - 864C-Bus-(模拟加油站问题)
https://vjudge.net/problem/CodeForces-864C 题意:两地之间有个加油站,往返走k个单程,最少加油多少次. 大佬几十行代码就解决,我却要用一百多行的if语句模拟解 ...
- Codeforces 709C 模拟
C. Letters Cyclic Shift time limit per test:1 second memory limit per test:256 megabytes input:stand ...
随机推荐
- 有趣的Ruby-学习笔记3
Ruby方法 方法名要以小写字母开头.假设用大写字母开头会被作为常量 (这点非常奇怪) 定义一个无參的方法 def method_name expr.. end 定义一个有參的方法 def metho ...
- TEA对称加密算法
今天在看<Distributed Systems Concepts and Design>这本书的时候,在讲到分布式系统的安全性的时候,给出了TEA算法,书本上有现成的代码,所以摘录下来以 ...
- poj 2154 Color < 组合数学+数论>
链接:http://poj.org/problem?id=2154 题意:给出两个整数 N 和 P,表示 N 个珠子,N种颜色,要求不同的项链数, 结果 %p ~ 思路: 利用polya定理解~定理内 ...
- asp.net mvc4 之Webapi之客户端或服务器端安全控制
一.WebAPI的工作方式 WebAPI的工作方式:HTTP的请求最先是被传递到HOST中的,如果WebAPI是被寄宿在IIS上的,这个HOST就是IIS上,HOST是没有能力也没有必 要进行请求的处 ...
- 九度OJ 1143:Primary Arithmetic(初等数学) (进位)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:616 解决:254 题目描述: Children are taught to add multi-digit numbers from ri ...
- Kotlin基本语法笔记3之定义类、继承及创建实例
定义类 class MyObject private constructor(name: String, age: Int) { private var name: String private va ...
- 阿里Java开发手册学习 3 MYSQL规约
@import url(http://i.cnblogs.com/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/c ...
- 基于地理位置信息的traceroute
我们在机房选择.測试网络的质量的时候,往往仅仅依据跳数.延迟.抖动.网络吞吐量等指标来衡量,非常多时候跳数并不能全然显示网络拓扑优劣,于是写了个traceroute结合whois的小脚本来直观显示每一 ...
- Linux常用命令——持续更新(2018-05-09)
此命令默认是在centos环境下执行,除非特殊标明. 1.查看ip: ifconfig 2.创建指定用户并分配到某个组:创建用户user并分配到root组 useradd -g root user 3 ...
- Post Man 调用CRMAPI
官方文档 https://docs.microsoft.com/en-us/dynamics365/customer-engagement/developer/webapi/setup-postman ...