Codeforces Round #568 (Div. 2) D. Extra Element
链接:
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的更多相关文章
- Codeforces Round #568 (Div. 2) 选做
A.B 略,相信大家都会做 ^_^ C. Exam in BerSU 题意 给你一个长度为 \(n\) 的序列 \(a_i\) .对于每个 \(i\in [1,N]\) 求 \([1,i-1]\) 中 ...
- Codeforces Round #445 Div. 1 C Maximum Element (dp + 组合数学)
题目链接: http://codeforces.com/contest/889/problem/C 题意: 给你 \(n\)和 \(k\). 让你找一种全排列长度为\(n\)的 \(p\),满足存在下 ...
- Codeforces Round #568 (Div. 2)B
B. Email from Polycarp 题目链接:http://codeforces.com/contest/1185/problem/B 题目: Methodius received an e ...
- Codeforces Round #568 (Div. 2)A
A. Ropewalkers 题目链接:http://codeforces.com/contest/1185/problem/A 题目: Polycarp decided to relax on hi ...
- codeforces Round #568(Div.2)A B C
有点菜,只写出了三道.活不多说,上题开干. A. Ropewalkers Polycarp decided to relax on his weekend and visited to the per ...
- 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 ...
- Codeforces Round #568 (Div. 2) B. Email from Polycarp
链接: https://codeforces.com/contest/1185/problem/B 题意: Methodius received an email from his friend Po ...
- Codeforces Round #568 (Div. 2) A.Ropewalkers
链接: https://codeforces.com/contest/1185/problem/A 题意: Polycarp decided to relax on his weekend and v ...
- Codeforces Round #568 (Div. 2) G1. Playlist for Polycarp (easy version) (状压dp)
题目:http://codeforces.com/contest/1185/problem/G1 题意:给你n给选项,每个选项有个类型和价值,让你选择一个序列,价值和为m,要求连续的不能有两个相同的类 ...
随机推荐
- Web05_jQuery
在官方网站下载包,下载不带有min的包 http://jquery.com/download/ 案例一:使用JQ完成首页定时弹出广告图片 01_JQ入门 01_jQuery入门.html <!D ...
- slideToggle()---单击隐藏/浮现--jQuery--click() 方法
click() 方法 模块隐藏/浮现 <html> <head> <script type="text/javascript" src="/ ...
- plsql连接本地oracle数据库,而远程主机却无法连接,出现无监听程序的解决方法(转)
原文转自:plsql连接本地oracle数据库,而远程主机却无法连接,出现无监听程序的解决方法 最近在使用plsql连接本地oracle数据库的时候,在同一网络环境中,出现了可以连接本地oracle, ...
- 【神经网络与深度学习】【CUDA开发】caffe-windows win32下的编译尝试
[神经网络与深度学习][CUDA开发]caffe-windows win32下的编译尝试 标签:[神经网络与深度学习] [CUDA开发] 主要是在开发Qt的应用程序时,需要的是有一个使用的库文件也只是 ...
- 【神经网络与深度学习】【Python开发】Caffe配置 windows下怎么安装protobuf for python
首先从google上下载protobuf-2.5.0.zip和protoc-2.5.0-win32.zip,然后把protoc-2.5.0-win32.zip里的protoc.exe放到protobu ...
- HTML5 plus 报错 Uncaught SyntaxError: Unexpected identifier at XXXX.html:1
最近使用 VUE2.X + muse-ui + HTML5 plus 开发webApp 调用HTML5 plus报错,错误提示如下 Uncaught SyntaxError: Unexpected ...
- 索引之----mysql单列索引失效的情况
使用的索引名称: 1.隐式转换导致索引失效. 由于表字段定义为vachar类型,但在查询时把该字段作为number类型 以及where条件传给mysql. 2.对索引列进行任何操作(计算(+.-.*. ...
- strtoul()引起的刷卡异常
)//10个字节 10进制数 { tempcard=strtoul((,);//将 cardnum[]=tempcard>>&0x00ff;//最高位 cardnum[]=temp ...
- python 传址 与传值(暂时保存,后续做分类)
# python 传址 与 传值 # 定义一个函数 用于将 list 下标为2的数据加100 并进行打印 该list def test1(list): list[2]+=100 print(list) ...
- css样式实例
* { box-sizing: border-box; } /*box-sizing属性允许您以特定的方式定义匹配某个区域的特定元素*/ body { font: Arial; margin:; } ...