Gym - 101848B Almost AP 暴力
题目链接: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 暴力的更多相关文章
- Codeforces Gym 100015H Hidden Code 暴力
Hidden Code 题目连接: http://codeforces.com/gym/100015/attachments Description It's time to put your hac ...
- Codeforces gym 100685 A. Ariel 暴力
A. ArielTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100685/problem/A Desc ...
- Codeforces Gym 100637G G. #TheDress 暴力
G. #TheDress Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100637/problem/G ...
- Gym 101055A 计算几何,暴力
http://codeforces.com/gym/101055/problem/A 题目:给定一些三维空间的点,要你找一个平面,能覆盖尽量多的点,只要求输出点数即可.n<=50 因为数据量小, ...
- Codeforces Gym 100203G Good elements 暴力乱搞
原题链接:http://codeforces.com/gym/100203/attachments/download/1702/statements.pdf 题解 考虑暴力的复杂度是O(n^3),所以 ...
- Codeforce Gym 100015I Identity Checker 暴力
Identity Checker 题目连接: http://codeforces.com/gym/100015/attachments Description You likely have seen ...
- code Gym 100500D T-shirts(暴力)
因为只能买一次,暴力枚举一下买的衣服的大小. #include<cstdio> #include<map> #include<algorithm> using na ...
- Gym 100342E Minima (暴力,单调队列)
3e7暴力,800ms+过,单调队列维护区间最小值. #include<bits/stdc++.h> using namespace std; typedef long long ll; ...
- Gym - 101194L World Cup 暴力
World CupInput file: Standard InputOutput file: Standard OuptutTime limit: 1 second Here is World Cu ...
随机推荐
- gtest 学习
mac 安装gtest 1.git clone https://github.com/google/googletest 2.cd googletest 3.brew install cmake如果没 ...
- Linux 文件目录管理命令
1.touch 用于设置空白文件或设置文件时间 touch命令参数及作用 参 数 ...
- 编程实现将一个N进制数转换成M进制数
问题:编程实现将一个N进制数转换成M进制数.(c/c++.Java.Javascript.C#.Python) 1.Python 手写算法版 def conversion_num(num, src, ...
- Spring @Autowired注解在非Controller中注入为null
问题描述 今天在写一个工具类,里面用了@Autowired注入了StringRedisTemplate以及RedisTemplate时,在template.opsForValue().set(key, ...
- delphi:Exception EInvalidPointer in module Project1.exe
在用delphi XE5编程时遇到如下问题: Exception EInvalidPointer in module Project1.exe at 00007595. Invalid pointer ...
- 有哪些api接口可以实现微信自动唤醒浏览器,下载app,打开网页
现在微信渠道可以说是拉新最快的渠道,因为微信具备强裂变性.但是目前微信对第三方下载链接的拦截是越来越严格了,那么想要在微信内肆无忌惮地推广链接就需要用到微信跳转浏览器的接口,那如何获取该接口呢? ...
- python之路:变量与变量基本操作(老王版)
python开发之路:变量与变量基本操作 你是一个师范大学的优秀毕业生,现在在某某小学工作. 你想:判作业真的很累,隔壁老王现在天天玩<蓝月传奇>,银行里存满了钱.唉,每节课1个小时,每个 ...
- 每日一练之大整数加法(P1255 数楼梯)
走楼梯走一步还是两步的问题其实就是斐波那契数列(F(n)=F(n-1)+F(n-2),而在int型范围内存在45个相异的数,题干说明楼梯总数可以为5000,则考虑使用字符串进行存储.当两个数相加产生进 ...
- Ontology理论研究和应用建模
转自:https://www.cnblogs.com/yes-V-can/p/8151275.html 目录 1 关于Ontology 1.1 Ontology的定义 1.2 Ontology的建模元 ...
- 浅谈Java堆内存分代回收
目录 1.概述 2.堆内存是如何分代的 3.各分代之间是如何配合工作的 1.概述 与C++不同的是, 在Java中我们无需关心对象占用空间的释放, 这主要得益于Java中的垃圾处理器(简称GC)帮助我 ...