题意:给定n个数,要求修改其中最少的数,使得这n个数满足ai + 1 - ai = k。

分析:

暴力,1000*1000。

1、这n个数,就是一个首项为a1,公差为k的等差数列。k已知,如果确定了a1,就能确定整个数列。

2、1 ≤ ai ≤ 1000,因此,可以从1~1000中枚举a1,将形成的数列与给定的数列比较,统计两数列对应下标中不同数字的个数。

3、不同数字的个数最少的那个数列就是最终要修改成的数列,然后输出对应下标的那个数的变化值即可。

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<sstream>
#include<iterator>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<deque>
#include<queue>
#include<list>
#define lowbit(x) (x & (-x))
const double eps = 1e-8;
inline int dcmp(double a, double b){
if(fabs(a - b) < eps) return 0;
return a > b ? 1 : -1;
}
typedef long long LL;
typedef unsigned long long ULL;
const int INT_INF = 0x3f3f3f3f;
const int INT_M_INF = 0x7f7f7f7f;
const LL LL_INF = 0x3f3f3f3f3f3f3f3f;
const LL LL_M_INF = 0x7f7f7f7f7f7f7f7f;
const int dr[] = {0, 0, -1, 1, -1, -1, 1, 1};
const int dc[] = {-1, 1, 0, 0, -1, 1, -1, 1};
const int MOD = 1e9 + 7;
const double pi = acos(-1.0);
const int MAXN = 1000 + 10;
const int MAXT = 10000 + 10;
using namespace std;
int a[MAXN];
int main(){
int n, k;
scanf("%d%d", &n, &k);
for(int i = 1; i <= n; ++i){
scanf("%d", &a[i]);
}
int id = 0;
int _min = 0x7f7f7f7f;
for(int i = 1; i <= 1000; ++i){
int cnt = 0;
for(int j = 1; j <= n; ++j){
if(a[j] != i + (j - 1) * k){
++cnt;
}
}
if(cnt < _min){
_min = cnt;
id = i;
}
}
printf("%d\n", _min);
for(int i = 1; i <= n; ++i){
if(a[i] != id + (i - 1) * k){
if(a[i] > id + (i - 1) * k){
printf("- %d %d\n", i, a[i] - id - (i - 1) * k);
}
else{
printf("+ %d %d\n", i, id + (i - 1) * k - a[i]);
}
}
}
return 0;
}

  

CodeForces - 402B Trees in a Row (暴力)的更多相关文章

  1. codeforces B. Trees in a Row 解题报告

    题目链接:http://codeforces.com/problemset/problem/402/B 题目意思:给出n个数和公差k,问如何调整使得ai + 1 - ai = k.(1 ≤ i < ...

  2. B. Trees in a Row(cf)

    B. Trees in a Row time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  3. Codeforces Gym 100002 C "Cricket Field" 暴力

    "Cricket Field" Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/1000 ...

  4. Codeforces Gym 100513M M. Variable Shadowing 暴力

    M. Variable Shadowing Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100513/ ...

  5. Codeforces Gym 100513G G. FacePalm Accounting 暴力

    G. FacePalm Accounting Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100513 ...

  6. Codeforces 839A Arya and Bran【暴力】

    A. Arya and Bran time limit per test:1 second memory limit per test:256 megabytes input:standard inp ...

  7. Codeforces 827E Rusty String - 快速傅里叶变换 - 暴力

    Grigory loves strings. Recently he found a metal strip on a loft. The strip had length n and consist ...

  8. Codeforces Beta Round #3 B. Lorry 暴力 二分

    B. Lorry 题目连接: http://www.codeforces.com/contest/3/problem/B Description A group of tourists is goin ...

  9. codeforces 673C C. Bear and Colors(暴力)

    题目链接: C. Bear and Colors time limit per test 2 seconds   memory limit per test 256 megabytes input s ...

随机推荐

  1. springboot#父项目

  2. Java图形与文本(18)

    实例018  旋转图形 实例说明 本实例演示在Java中绘制图形时,如何对图形进行旋转.运行程序,单击窗体上的“顺时针”按钮,可以将图形顺时针旋转,效果如图1.18所示,用户还可以通过单击“逆时针”和 ...

  3. CRM:异步加载下拉列表,三个列表出现同样的下拉框

    异步加载下拉列表,三个列表出现同样的下拉框,原因如下: Spring默认单例,如果Action是单例,那么上一次查询的结果就可能被下一次的查询所调用.所以必须配置action为多例, 如果采用单例模式 ...

  4. day06-Python运维开发基础(字符串格式化与相关的函数、列表相关的操作)

    1. 字符串相关的操作与格式化 # ### 字符串相关操作 # (1)字符串的拼接 + var1 = "亲爱的," var2 = "男孩" res = var1 ...

  5. ROS学习笔记2-基本概念

    本笔记来源于:http://wiki.ros.org/ROS/Concepts ROS文件系统级别文件系统级别主要包含了你能在ROS的磁盘上遇到的资源,包括: 包(Packages):包是ROS中资源 ...

  6. python 字符串实例:检查并判断密码字符串的安全强度

    检查并判断密码字符串的安全强度 import string def check(pwd): #密码必须至少包含六个字符 if not isinstance(pwd,str) or len(pwd)&l ...

  7. C中的文件操作函数[笔记]

    头件 : #include<stdio.h> 两个必须函数: FILE * fopen(const char * path,const char * mode); //path:文件路径 ...

  8. JVM:垃圾回收

    概述 上一篇文章我们已经了解了 Java 的这几块内存区域.对于垃圾回收来说,针对或者关注的是 Java 堆这块区域.因为对于程序计数器.栈.本地方法栈来说,他们随线程而生,随线程而灭,所以这个区域的 ...

  9. flutter安装中的一些方法

    1.配置flutter环境变量 进入终端 vim ~/.bash_profile export ANDROID_HOME=~Library/Android/sdk export PATH=$PATH: ...

  10. Ubuntu 14.04 配置 VNC Server

    用putty连接Linux后,如果会话断开,也会终止此会话在Linux执行的任务. 用WinSCP传输文件很方便,目前也只能传输文件. 按照以下步骤以及提示,安装VNC Server, 1.apt-g ...