CodeForces - 402B Trees in a Row (暴力)
题意:给定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 (暴力)的更多相关文章
- codeforces B. Trees in a Row 解题报告
题目链接:http://codeforces.com/problemset/problem/402/B 题目意思:给出n个数和公差k,问如何调整使得ai + 1 - ai = k.(1 ≤ i < ...
- 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 ...
- Codeforces Gym 100002 C "Cricket Field" 暴力
"Cricket Field" Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/1000 ...
- Codeforces Gym 100513M M. Variable Shadowing 暴力
M. Variable Shadowing Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100513/ ...
- Codeforces Gym 100513G G. FacePalm Accounting 暴力
G. FacePalm Accounting Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100513 ...
- Codeforces 839A Arya and Bran【暴力】
A. Arya and Bran time limit per test:1 second memory limit per test:256 megabytes input:standard inp ...
- Codeforces 827E Rusty String - 快速傅里叶变换 - 暴力
Grigory loves strings. Recently he found a metal strip on a loft. The strip had length n and consist ...
- Codeforces Beta Round #3 B. Lorry 暴力 二分
B. Lorry 题目连接: http://www.codeforces.com/contest/3/problem/B Description A group of tourists is goin ...
- codeforces 673C C. Bear and Colors(暴力)
题目链接: C. Bear and Colors time limit per test 2 seconds memory limit per test 256 megabytes input s ...
随机推荐
- day10-Python运维开发基础(函数嵌套、nonlocal声明局部变量、闭包、locals/globals、lambda表达式)
1. 函数的嵌套与nonlocal 声明局部变量 # ### 函数的嵌套 """ 函数和函数之间可以互相嵌套: 嵌套在内层的叫做内函数 乔涛在外层的叫做外函数 " ...
- 分页插件 layui.laypage 的用法
参考 layui.laypage 官方文档 https://www.layui.com/demo/laypage.html 第一步下载插件 (注意不能只引入引入 layui.css和layui.js ...
- IOS TableView 用法
1.在视图上创建TableView( 拖控件),为ViewController创建UITableView属性(链接至TableView)和NSArray属性(存储数据) ViewController. ...
- 1-2SpringBoot项目属性配置
前面我们讲解了SpringBoot HelloWorld实现 今天具体来讲解上那个application.properties项目配置文件 打开是空白 里面可以配置项目,所以配置项目我们 alt+/ ...
- SSH框架系列:Spring读取配置文件以及获取Spring注入的Bean
分类: [java]2013-12-09 16:29 1020人阅读 评论(0) 收藏 举报 1.简介 在SSH框架下,假设我们将配置文件放在项目的src/datasource.properties路 ...
- Tomcat+JSP经典配置实例
经常看到jsp的初学者问tomcat下如何配置jsp.servlet和bean的问题,于是总结了一下如何tomcat下配置jsp.servlet和ben,希望对那些初学者有所帮助. 一.开发环境配置 ...
- 【Luogu2496】【BZOJ3005】[SDOI2012]体育课
把自己去年在luogu写的一个题解搬过来 原题解链接 1. 题目大意 给定一个长度为 \(n\) 的数列 \(a_1,a_2,a_3,...,a_n\) , 并给出 \(m\) 个操作,操作类型如下: ...
- 十一 Socket编程
一. 计算机网络: 将地理位置不同的具有独立功能的多台计算机及其外部设备,通过通信线路连接起来在网络操作系统.网络管理软件及网络通信协议的管理和协调下,实现资源共享和信息传递的计算机系统 二. ...
- jdk1.7推出的Fork/Join提高业务代码处理性能
jdk1.7推出的Fork/Join提高业务代码处理性能 jdk1.7之后推出了Fork/Join框架,其原理个人理解为:递归多线程并发处理业务代码,以下为我模拟我们公司业务代码做的一个案例,性能可提 ...
- python-python基础3
本章内容: 函数 递归 高阶函数 一.函数 一个函数一般完成一项特定的功能 函数使用 函数需要先定义 使用函数,调用