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,要求连续的不能有两个相同的类 ...
随机推荐
- 如何在 Spring/Spring Boot 中做参数校验
数据的校验的重要性就不用说了,即使在前端对数据进行校验的情况下,我们还是要对传入后端的数据再进行一遍校验,避免用户绕过浏览器直接通过一些 HTTP 工具直接向后端请求一些违法数据. 本文结合自己在项目 ...
- javase程序设计上机作业2
package javaxgp.teacher.test; import java.util.Scanner; public class Demo3 { public static void main ...
- ubuntu16.04离线安装nvidia-docker2
目前需要离线对ubuntu 进行封装docker环境 在熟悉docker环境过程中,有网络条件下,还处于懵逼状态 离线安装…… 大佬救救我 来了: 首先下载安装docker最新版 我的OS是Ubunt ...
- C语言I博客作业12-学期总结
一.我学到的内容 二.我的收获 1. https://www.cnblogs.com/1076022899-lj/p/11576442.html 收获:第一次接触到C语言和PTA,第一次学习了博客园和 ...
- ubuntu修改时间为北京时间
ubuntu修改时间为北京时间 查看当前时区root@ubuntu:/# date -R修改时区root@ubuntu:/# tzselect复制文件到/etc目录下root@ubuntu:/# cp ...
- [gym101981D][2018ICPC南京D题]Country Meow
题目链接 题目大意是求三维空间可以包含$n$个点的最小圆半径. 如果有做过洛谷P1337就会发现这到题很模拟退火,所以就瞎搞一发. $PS:$注意本题时限$3$秒. #include<bits/ ...
- trigraph
trigraph是c/c++对之前键盘无法输入一些符号而做出的补充设计,将以下字符用其他三个字符来代替 # ??= \ ??/ ^ ??' [ ??( ] ??) { ??< } ??> ...
- kafka 教程(四)-原理进阶
kafka 最初由 Linkedin 公司开发,是一个 分布式.支持分区.多副本的,基于 zookeeper 协调的分布式发布订阅消息系统,该公司在 2010 年将 kafka 贡献给 apache ...
- 数据库中的round()
Round函数返回一个数值,该数值是按照指定的小数位数进行四舍五入运算的结果.可是当保留位跟着的即使是5,有可能进位,也有可能舍去,机会各50%.这样就会造成在应用程序中计算有误. 参数规范 语法 r ...
- Linux服务器应急事件溯源报告
Linux服务器应急事件溯源报告 小博博 · 2016/02/18 17:43 Author:Inn0team 0x00 目录 关于目标环境的中间进度检测报告 一:情况概述 二:取证情况 2.1 目标 ...