链接:

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. Android IdleHandler 原理浅析

    IdleHandler:空闲监听器(就像我没事做了,在群里发了个表情,这时候其他人就知道我很闲了) 在每次next获取消息进行处理时,发现没有可以处理的消息(队列空,只有延时消息并且没到时间,同步阻塞 ...

  2. 依赖注入——angular

    在Angular中创建一个对象时,需要依赖另一个对象,这是代码层的一种依赖关系,当这种依赖被声明后,Angular通过injector注入器将所依赖的对象进行注入操作. 一.依赖注入的原理 看下面的示 ...

  3. JDBC操作数据库的基本操作

    JDBC操作数据库的基本步骤: 1)加载(注册)数据库驱动(到JVM). 2)建立(获取)数据库连接. 3)创建(获取)数据库操作对象. 4)定义操作的SQL语句. 5)执行数据库操作. 6)获取并操 ...

  4. THUWC2019(?)历险记

    Day \(-?\) 搞文化. Day \(-4\) 突然发现自己复活了,然后就来机房了( Day \(-3\) 返 璞 归 真, 开 始 骆 氪 上午考试,被吊打了/kk Day \(-2\) 上午 ...

  5. 使用 Unity* 进行并行处理的一种方法

    本文展示如何使用 Unity* 对游戏进行并行处理,以及如何使用游戏引擎执行与游戏相关的物理.在这个领域内,现实感是成功的一个重要标志.为了模拟真实世界,许多动作需要同时发生,这需要并行处理.创建两个 ...

  6. Shell编程、part3

    本节内容 1. shell流程控制 2. for语句 3. while语句 4. break和continue语句 5. case语句 6. shell编程高级实战 shell流程控制 流程控制是改变 ...

  7. [开发技巧]·Python实现信号滤波(基于scipy)

    [开发技巧]·Python实现信号滤波(基于scipy) 个人网站--> http://www.yansongsong.cn GitHub主页--> https://github.com/ ...

  8. layer最大话.最小化.还原回调方法

    layer.open({              type: 1,             title: ‘在线调试‘,           content: ‘这里是内容‘,            ...

  9. junction 文件夹做连接到别的分区

    加载连接 C:\>junction "C:\Docume~1\Admini~1\LocalS~1\Applic~1\360Chr~1\Chrome\UserDa~1\Default&q ...

  10. airflow部署

    官网: http://airflow.apache.org/installation.html 原理: https://www.cnblogs.com/cord/p/9450910.html 安装: ...