题目链接:http://codeforces.com/gym/101848/problem/B

给出一串数字要你最多改动三个数字使这一串数字成为等差数列。因为最多改动三个数字所以可以先求出相邻两项的差值再进行修改,判断是否符合,最多循环四遍即可。

#include<iostream>
using namespace std;
int main()
{
int n,a[],b[];
cin>>n;
for(int i=;i<n;i++)
cin>>a[i];
if(n<=)
{
for(int i=;i<n;i++)
b[i]=a[];
}
else
{
for(int i=n-;i>=;i--)//正着循环会wa12,反过来就ac了,特别的迷
{
int c,cnt=;
if(i!=n-)c=a[i+]-a[i];
else c=a[i]-a[i-];
b[i]=a[i];
for(int j=i-;j>=;j--)
{
if(a[j]==a[i]+(j-i)*c)b[j]=a[j];
else
{
b[j]=a[i]+(j-i)*c;
cnt++;
}
}
if(cnt>)continue;
for(int j=i+;j<n;j++)
{
if(a[j]==a[i]+(j-i)*c)b[j]=a[j];
else
{
b[j]=a[i]+(j-i)*c;
cnt++;
}
if(cnt>)break;
}
if(cnt>)continue;
else break;
}
}
for(int i=;i<n;i++)
{
if(i!=n-)cout<<b[i]<<" ";
else cout<<b[i]<<endl;
}
return ;
}

Gym - 101848B Almost AP 暴力的更多相关文章

  1. Codeforces Gym 100015H Hidden Code 暴力

    Hidden Code 题目连接: http://codeforces.com/gym/100015/attachments Description It's time to put your hac ...

  2. Codeforces gym 100685 A. Ariel 暴力

    A. ArielTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100685/problem/A Desc ...

  3. Codeforces Gym 100637G G. #TheDress 暴力

    G. #TheDress Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100637/problem/G ...

  4. Gym 101055A 计算几何,暴力

    http://codeforces.com/gym/101055/problem/A 题目:给定一些三维空间的点,要你找一个平面,能覆盖尽量多的点,只要求输出点数即可.n<=50 因为数据量小, ...

  5. Codeforces Gym 100203G Good elements 暴力乱搞

    原题链接:http://codeforces.com/gym/100203/attachments/download/1702/statements.pdf 题解 考虑暴力的复杂度是O(n^3),所以 ...

  6. Codeforce Gym 100015I Identity Checker 暴力

    Identity Checker 题目连接: http://codeforces.com/gym/100015/attachments Description You likely have seen ...

  7. code Gym 100500D T-shirts(暴力)

    因为只能买一次,暴力枚举一下买的衣服的大小. #include<cstdio> #include<map> #include<algorithm> using na ...

  8. Gym 100342E Minima (暴力,单调队列)

    3e7暴力,800ms+过,单调队列维护区间最小值. #include<bits/stdc++.h> using namespace std; typedef long long ll; ...

  9. Gym - 101194L World Cup 暴力

    World CupInput file: Standard InputOutput file: Standard OuptutTime limit: 1 second Here is World Cu ...

随机推荐

  1. [python爬虫] Selenium常见元素定位方法和操作的学习介绍

    这篇文章主要Selenium+Python自动测试或爬虫中的常见定位方法.鼠标操作.键盘操作介绍,希望该篇基础性文章对你有所帮助,如果有错误或不足之处,请海涵~同时CSDN总是屏蔽这篇文章,再加上最近 ...

  2. sqlserver一些对象的创建

    1.db_link 一 如何创建Dblink1)SQLServer 到 SQLServerExec sp_droplinkedsrvlogin PDALink,Null --删除映射(录与链接服务器上 ...

  3. 有了这个api接口工具-微信跳转其他浏览器下载app就这么简单

    现在微信渠道可以说是拉新最快的渠道,因为微信具备强裂变性.但是目前微信对第三方下载链接的拦截是越来越严格了,那么想要在微信内肆无忌惮地推广链接就需要用到微信跳转浏览器的api接口,那如何获取该api接 ...

  4. activiti官网实例项目activiti-explorer实操详情

    参考链接:https://www.xuchuruo.cn/Activiti-modeler%E6%95%B4%E5%90%88%E5%88%B0Spring.html 按照链接文章提示操作完成之后,启 ...

  5. python回归分析

    假设原函数由一个三角函数和一个线性项组成 import numpy as np import matplotlib.pyplot as plt %matplotlib inline def f(x): ...

  6. mysql join优化原理

    http://blog.itpub.net/22664653/viewspace-1692317/ http://itindex.net/detail/46772-%E4%BC%98%E5%8C%96 ...

  7. bashrc和bash_profile

    在~/.bashrc中起别名 !/bin/bash下必须加上shopt -s expand_aliases #!/bin/sh下不用 shopt -s expand_aliases 这一条命令让she ...

  8. Mac gitk安装与优化

    一.mac系统安装gitk gitk是git的一个bin工具,如果git不包含gitk只能说明当前使用的git版本过老. 因此我们只需要安装最新的git就可以了.安装git方法如下: 首先安装brew ...

  9. yarn安装及node升级

    ERROR: root@debian:/home/test/keygen-radio-master/scripts# npm install -g yarn npm WARN engine yarn@ ...

  10. Double 保留小数点后N位

    /** * parse double f to num decimals * @param f * @param num the decimal number * @return the format ...