链接:

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组件TStringlist中的重复项目

    https://blog.csdn.net/ozhy111/article/details/87975663 删除delphi组件TStringlist中的重复项目 2019年02月27日 15:41 ...

  2. 项目中使token

    项目中使token 如果项目架构采用前后端分离,并采用分布式架构,通过定义接口API,与前端进行数据交互,前端通过html前行实现.若加入移动端(Andriod,ios)实现,可直接使用API接口实现 ...

  3. eureka和zookeeper的区别?

    eureka和zookeeper都可以提供服务注册与发现的功能,       zookeeper 是CP原则,强一致性(consistency)和分区容错性(Partition).       eur ...

  4. Studio 3T 破解教程

    亲测可用 ,且小编一直在使用 1.创建文件studio3t.bat 并将下面这段内容复制 @echo off ECHO 重置Studio 3T的使用日期...... FOR /f "toke ...

  5. [转帖]站点部署,IIS配置优化指南

    站点部署,IIS配置优化指南 https://www.cnblogs.com/heyuquan/p/deploy-iis-set-performance-guide.html 挺值得学习的 毕竟之前很 ...

  6. DIY兼容机装苹果系统

    遇到问题: 无法用变色龙引导:删除原WIN系统前隐藏分区 变色龙引导画面无法进安装界面:a,wowpc.iso版本低,换新版;b,复制EXTRA进MAC安装盘 MAC OS安装完成后重新启动卡在苹果图 ...

  7. 树型DP入门

    题意: 某公司要举办一次晚会,但是为了使得晚会的气氛更加活跃,每个参加晚会的人都不希望在晚会中见到他的直接上司,现在已知每个人的活跃指数和上司关系(当然不可能存在环),求邀请哪些人(多少人)来能使得晚 ...

  8. python3 修改大数据量excel内容

    最好使用python3 64位 对excel的修改操作: from openpyxl import load_workbook import time #打开一个excel表格.xlsx wb = l ...

  9. JavaScript应懂的概念

    目录 垃圾回收 函数作用域, 块级作用域和词法作用域 调用堆栈 原始类型 值类型和引用类型 隐式, 显式, 名义和鸭子类型 == 与 ===, typeof 与 instanceof this, ca ...

  10. 常用的框架伪静态(Apache转Nginx)

    EmpireCMS: rewrite ^([^\.]*)/listinfo-(.+?)-(.+?)\.html$ $/e/action/ListInfo/index.php?classid=$& ...