题目链接: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. zookeeper启动报 Unexpected exception, exiting abnormally 错误

    启动zookeeper---jps,未出现QuorumPeerMain进程 原因: 电脑中的某些进程占用了2181 port 通过 sudo netstat -nltp|grep 2181查看进程并k ...

  2. LeetCode 203. Remove Linked List Elements 移除链表元素 C++/Java

    Remove all elements from a linked list of integers that have value val. Example: Input: ->->-& ...

  3. Docker 开启 remoter api

    debian 环境: vi /lib/systemd/system/dcoker.service 修改: ExecStart=/usr/bin/dockerd -H fd://为 ExecStart= ...

  4. django 创建视图和APP

    .创建视图views 1.在项目目录下创建views.py文件 2.from django.http import HttpResponse 3.在urls 导入模板: from django.con ...

  5. MYSQL临时表使用方法

    当工作在非常大的表上时,你可能偶尔需要运行很多查询获得一个大量数据的小的子集,不是对整个表运行这些查询,而是让MySQL每次找出所需的少数记录,将记录选择到一个临时表可能更快些,然后在这些表运行查询. ...

  6. VS编写一个项目的路径规划

    原文路径:http://blog.csdn.net/puttytree/article/details/7838419 https://www.cnblogs.com/zhehan54/p/45678 ...

  7. 每日算法之递推排序(P1866 编号)

    兔子也是数字控:每个兔子都有自己喜欢的数字区间,找出能让所有兔子都满意的组合. 将所有兔子喜欢的序号按从小到大排序,此时如果小序号的兔子选择了一个数字,则之后的兔子只要排除排在它之前的兔子数(由于已经 ...

  8. python学习Day6 元组、字典、集合set三类数据用法、深浅拷贝

    一.深浅拷贝 1.  值拷贝 ls1 = ls2  不开辟空间,指针跟着走.(直接将ls1中存放的地址拿过来,内存中不会开辟新的空间,所以你怎么变,我也跟着变.)(ls1内部的所有类型的值发生改变,l ...

  9. OpenCV4.0学习笔记

    1.读取显示图像 #include<opencv2/opencv.hpp> #include<iostream> using namespace cv; using names ...

  10. oracl遇到的问题

    使用oracl数据库用  ALTER TABLE Students ADD CONSTRAINT PRINF_NAME_UNIQUE UNIQUE (sname) 添加唯一性约束,出现问题,报错为:a ...