题意:给定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. VUE 父子组件之间通信传值 props和 $emit

    1.父组件传值给子组件 $props,子组件传值给父组件 $emit 父组件          <div id="app" >               <tr ...

  2. SQL语言的四种类型

    SQL语言共分为四大类:数据查询语言DQL,数据操纵语言DML,数据定义语言DDL,数据控制语言DCL. 1. 数据查询语言DQL 数据查询语言DQL基本结构是由SELECT子句,FROM子句,WHE ...

  3. java学习-初级入门-面向对象①-面向对象概述-结构化程序设计

    为了学习面向对象程序设计,今天我们先利用面向对象以前的知识,设计一个学生类. 要求进行结构化程序设计. 学生类: Student 要求:存储学生的基本信息(姓名.性别.学历层次和年级),实现学生信息的 ...

  4. 输入、输出(iostream)

    在一个程序当中输入和输出都扮演着重要的角色,所以掌握基本输入输出是入门一门语言所必不可少的.本文主要简单叙述java的输入和输出. package ios; import java.util.Scan ...

  5. Day3-J-4 Values whose Sum is 0 POJ2785

    The SUM problem can be formulated as follows: given four lists A, B, C, D of integer values, compute ...

  6. 「USACO08JAN」电话线Telephone Lines

    传送门 Luogu 解题思路 考虑二分,每次把大于二分值的边的权设为1,小于等于的设为0,如果最短路<=k则可行,记得判无解 细节注意事项 咕咕咕 参考代码 #include <algor ...

  7. Unity内置shader 下载

    Unity内置shader  4.3.1 版本的  其他版本可以自己修改名称 下载地址 http://download.unity3d.com/download_unity/builtin_shade ...

  8. Linux下如何拷贝整个目录下的所有文件

    分类: Linux使用2014-01-14 13:38 1449人阅读 评论(0) 收藏 举报 如何在Linux下拷贝一个目录呢?这好像是再如意不过的问题了.比如要把/home/usera拷贝到/mn ...

  9. eot文件

    *.eot文件 是一种压缩字库,目的是解决在网页中嵌入特殊字体的难题2.在网页中嵌入的字体只能是 OpenType 类型,其他类型的字体只有转换成 OpenType 类型(eot格式)的字体才能在网页 ...

  10. 题解 hdu4624 Endless Spin

    题目链接 题目大意: 有长度为\(n\)的区间,每次随机选择一段(左右端点都是整数)染黑,问期望多少次全部染黑. \(n\leq 50\) 设\(n\)个随机变量\(t_1,...,t_n\).\(t ...