链接:

https://codeforces.com/contest/1185/problem/D

题意:

A sequence a1,a2,…,ak is called an arithmetic progression if for each i from 1 to k elements satisfy the condition ai=a1+c⋅(i−1) for some fixed c.

For example, these five sequences are arithmetic progressions: [5,7,9,11], [101], [101,100,99], [13,97] and [5,5,5,5,5]. And these four sequences aren't arithmetic progressions: [3,1,2], [1,2,4,8], [1,−1,1,−1] and [1,2,3,3,3].

You are given a sequence of integers b1,b2,…,bn. Find any index j (1≤j≤n), such that if you delete bj from the sequence, you can reorder the remaining n−1 elements, so that you will get an arithmetic progression. If there is no such index, output the number -1.

思路:

排序后,先检测一开头,或者以结尾开始检测,不满足等差数列跳过,判断跳过了几个,大于1则不能。

代码:

#include <bits/stdc++.h>
using namespace std; typedef long long LL;
const int MAXN = 2e5+10;
int a[MAXN];
map<int, int> Mp;
int n; int Check(int fir, int sub)
{
int cnt = 0;
int res = Mp[a[1]];
for (int i = 1;i <= n;i++)
{
if (a[i] != fir)
{
cnt++;
res = Mp[a[i]];
}
else
fir += sub;
}
if (cnt > 1)
return -1;
else
return res;
} int main()
{
cin >> n;
for (int i = 1;i <= n;i++)
cin >> a[i], Mp[a[i]] = i;
sort(a+1, a+1+n);
if (n <= 3)
{
cout << 1 << endl;
return 0;
}
int res1 = Check(a[1], a[2]-a[1]); int res2 = Check(a[n]-(n-2)*(a[n]-a[n-1]), a[n]-a[n-1]);
if (res1 != -1)
cout << res1 << endl;
else if (res2 != -1)
cout << res2 << endl;
else
cout << -1 << endl; return 0;
}

Codeforces Round #568 (Div. 2) D. Extra Element的更多相关文章

  1. Codeforces Round #568 (Div. 2) 选做

    A.B 略,相信大家都会做 ^_^ C. Exam in BerSU 题意 给你一个长度为 \(n\) 的序列 \(a_i\) .对于每个 \(i\in [1,N]\) 求 \([1,i-1]\) 中 ...

  2. Codeforces Round #445 Div. 1 C Maximum Element (dp + 组合数学)

    题目链接: http://codeforces.com/contest/889/problem/C 题意: 给你 \(n\)和 \(k\). 让你找一种全排列长度为\(n\)的 \(p\),满足存在下 ...

  3. Codeforces Round #568 (Div. 2)B

    B. Email from Polycarp 题目链接:http://codeforces.com/contest/1185/problem/B 题目: Methodius received an e ...

  4. Codeforces Round #568 (Div. 2)A

    A. Ropewalkers 题目链接:http://codeforces.com/contest/1185/problem/A 题目: Polycarp decided to relax on hi ...

  5. codeforces Round #568(Div.2)A B C

    有点菜,只写出了三道.活不多说,上题开干. A. Ropewalkers Polycarp decided to relax on his weekend and visited to the per ...

  6. Codeforces Round #568 (Div. 2) C2. Exam in BerSU (hard version)

    链接: https://codeforces.com/contest/1185/problem/C2 题意: The only difference between easy and hard ver ...

  7. Codeforces Round #568 (Div. 2) B. Email from Polycarp

    链接: https://codeforces.com/contest/1185/problem/B 题意: Methodius received an email from his friend Po ...

  8. Codeforces Round #568 (Div. 2) A.Ropewalkers

    链接: https://codeforces.com/contest/1185/problem/A 题意: Polycarp decided to relax on his weekend and v ...

  9. Codeforces Round #568 (Div. 2) G1. Playlist for Polycarp (easy version) (状压dp)

    题目:http://codeforces.com/contest/1185/problem/G1 题意:给你n给选项,每个选项有个类型和价值,让你选择一个序列,价值和为m,要求连续的不能有两个相同的类 ...

随机推荐

  1. Delphi中的Free和Nil和freeandnil函数

    Delphi中的Free和Nil 在Delphi中释放对象资源时一般用Obj.Free(Obj为一个实例名),不过程Delphi中还有一个FreeAndNil(对象名)函数,那么用哪个好呢?Free和 ...

  2. Oracle 笔记(一)

    Oracle基本理论 l  主流数据库 微软公司:SQL Server  ACCESS IBM公司:DB2  infomix Oracle公司:Oracle  MySQL(AB公司) 小型数据库 AC ...

  3. java:LeakFilling(JSP,servlet,Ajax,Json,Path)

    1. request.setAttribute("test", "测试");       request.getRequestDispatcher(" ...

  4. 《React+Redux前端开发实战》笔记2:基于Webpack构建的Hello World案例(上)

    这次搭建分为两部分:一部分是前期必要配置,一部分是开发React代码. [基于Webpack的React Hello World项目] 1.前期必要配置 (1)首先要确保读者的开发设备上已经安装过No ...

  5. python 并发编程 多线程 定时器

    定时器 就是隔多长时间去触发任务执行 指定n秒后执行某操作 Timer如何使用,看Timer源码 class Timer(Thread): """Call a funct ...

  6. C# StreamReader与StreamWriter

    原文:https://www.cnblogs.com/kissdodog/archive/2013/01/27/2878667.html StreamReader实现了抽象基类TextReader类, ...

  7. 推荐几本Python书

    Python的书很多,由于python本身应用的领域太多,涉及方方面面的,因此书籍的种类也很多,下面是我推荐一些比较好的python书给大家,大家可以找一两本修炼,定能让你的功力大增. 1.A byt ...

  8. Maven出错的问题处理

    1:使用Maven部署dubbox.jar包到maven本地仓库 由于Dubbox的jar包并没有部署到Maven的中央仓库中,大家在Maven的中央仓库中可以查找到Dubbo的最终版本是2.5.3 ...

  9. php常用header状态

    <?php //200 正常状态 header('HTTP/1.1 200 OK'); // 301 永久重定向,记得在后面要加重定向地址 Location:$url header('HTTP/ ...

  10. 学习WPF-1

    学习WPF-1 最近到新公司,需要使用WPF来做界面开发,我原先是使用WinForm来做界面开发的,所以对于现在使用WPF来开发,需要先学习一段时间了,考核的内容目前也还没定下来做什么, 但终归是使用 ...