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 ...
随机推荐
- C#通过COM组件调用IDL的pro程序
如果在“COM_IDL_connectLib.COM_IDL_connect oComIDL = new COM_IDL_connectLib.COM_IDL_connect();”步骤提示“...8 ...
- Grafana短信报警实现
1.阿里云短信服务API2.Jenkins-plugin:Generic Webhook Trigger Plugin 阿里云 下载阿里云短信服务SDK 创建短信服务ACCESS_KEY_ID Gra ...
- Spring引入外部项目Junit 报ClassNotfound问题
https://blog.csdn.net/sheng_Mu555/article/details/80465679 用它这个方法可以了 所以大家可以过去看一下哈哈
- docker镜像无法下载或者下载缓慢
解决docker镜像无法下载的问题 2015年10月02日 16:01:05 阅读数:20776 克服跨洋网络延迟,使用Docker Hub Mirror加速Docker官方镜像下载 http://c ...
- Mysql出现(10061)错误提示的暴力解决办法
上个月我还在说别人的怎么老是会错呢,我的就没事,嘿 今天就轮到我了 我发誓 我绝对没碰它 是它先动的手 言归正传 下面给你们 介绍 终极大招 为什么是终极大招呢 因为网上那些前辈们的方法我都试 ...
- leetcode268缺失数字
int missingNumber(int* nums, int numsSize) { ) /; ;i<numsSize;i++){ sum = sum - nums[i]; } return ...
- jq 获取下一个兄弟原素 下拉箭头旋转
$('.weui-cells__title').on("click", function(e,rr){ isshow=$(this).attr('isshow') if(issho ...
- Mha-Atlas-MySQL高可用方案实践(二)
六,配置VIP漂移 主机名 IP地址(NAT) 漂移VIP 描述 mysql-db01 eth0:192.168.0.51 VIP:192.168.0.60 系统:CentOS6.5(6.x都可以) ...
- 宝塔面板安装在根目录www下
不能重装,重装防火墙要重新关闭. 安装时要主要更改文件权限.
- react axios 配置
1:package.json 添加 "proxy": "代理地址" 2 封装axios 创建server.js 添加 import a ...