codeforces402B
Trees in a Row
The Queen of England has n trees growing in a row in her garden. At that, the i-th (1 ≤ i ≤ n) tree from the left has height ai meters. Today the Queen decided to update the scenery of her garden. She wants the trees' heights to meet the condition: for all i (1 ≤ i < n), ai + 1 - ai = k, where k is the number the Queen chose.
Unfortunately, the royal gardener is not a machine and he cannot fulfill the desire of the Queen instantly! In one minute, the gardener can either decrease the height of a tree to any positive integer height or increase the height of a tree to any positive integer height. How should the royal gardener act to fulfill a whim of Her Majesty in the minimum number of minutes?
Input
The first line contains two space-separated integers: n, k (1 ≤ n, k ≤ 1000). The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 1000) — the heights of the trees in the row.
Output
In the first line print a single integer p — the minimum number of minutes the gardener needs. In the next p lines print the description of his actions.
If the gardener needs to increase the height of the j-th (1 ≤ j ≤ n) tree from the left by x (x ≥ 1) meters, then print in the corresponding line "+ j x". If the gardener needs to decrease the height of the j-th (1 ≤ j ≤ n) tree from the left by x (x ≥ 1) meters, print on the corresponding line "- j x".
If there are multiple ways to make a row of trees beautiful in the minimum number of actions, you are allowed to print any of them.
Examples
4 1
1 2 1 5
2
+ 3 2
- 4 1
4 1
1 2 3 4
0 sol:数据范围小的可怜,爆枚一个正确节点,n2模拟即可
#include <bits/stdc++.h>
using namespace std;
typedef int ll;
inline ll read()
{
ll s=;
bool f=;
char ch=' ';
while(!isdigit(ch))
{
f|=(ch=='-'); ch=getchar();
}
while(isdigit(ch))
{
s=(s<<)+(s<<)+(ch^); ch=getchar();
}
return (f)?(-s):(s);
}
#define R(x) x=read()
inline void write(ll x)
{
if(x<)
{
putchar('-'); x=-x;
}
if(x<)
{
putchar(x+''); return;
}
write(x/);
putchar((x%)+'');
return;
}
#define W(x) write(x),putchar(' ')
#define Wl(x) write(x),putchar('\n')
const int N=;
int n,m,a[N],b[N],Ans[N];
int main()
{
int i,j,Pos=-;
R(n); R(m);
for(i=;i<=n;i++) R(a[i]);
for(i=;i<=n;i++)
{
Ans[i]=;
b[i]=a[i];
for(j=i-;j>=;j--) b[j]=b[j+]-m;
for(j=i+;j<=n;j++) b[j]=b[j-]+m;
for(j=;j<=n;j++)
{
if(b[j]!=a[j]) Ans[i]++;
if(b[j]<=) {Ans[i]=0x3f3f3f3f; break;}
}
if((Pos==-)||(Ans[i]<Ans[Pos])) Pos=i;
}
Wl(Ans[Pos]);
b[Pos]=a[Pos];
for(i=Pos-;i>=;i--) b[i]=b[i+]-m;
for(i=Pos+;i<=n;i++) b[i]=b[i-]+m;
for(i=;i<=n;i++) if(a[i]!=b[i])
{
if(a[i]<b[i])
{
putchar('+'); putchar(' '); W(i); Wl(b[i]-a[i]);
}
else
{
putchar('-'); putchar(' '); W(i); Wl(a[i]-b[i]);
}
}
return ;
}
/*
Input
4 1
1 2 1 5
Output
2
+ 3 2
- 4 1 Input
4 1
1 2 3 4
Output
0
*/
codeforces402B的更多相关文章
随机推荐
- zookeeper初识
ZOOKEEPER是为分布式系统提供高性能的协调工具 角色: 1.领导者(leader):负责进行投票的发起和决议,更新系统状态2.学习者(learner):包括跟随者(follower)和观察者(o ...
- Scala学习五——类
一.本章要点 类中的字段自动带有getter方法和setter方法 你可以用定制的getter/setter方法替换掉字段的定义,而不必修改使用类的客户端——这就是所谓的”统一访问原则“ 用@Bean ...
- centos7安装配置NFS文件共享存储
一,环境介绍 本实验使用了两台centos7虚拟机,其中 服务器:192.168.1.188 客户端:192.168.1.189 二,实验步骤 192.168.1.1 ...
- Springboot Hikari Centos 首次连数据库很慢
前言: springboot项目默认使用了hikari作为数据库连接池,在开发机器上一切正常. 但是把程序部署到Centos7 x64上之后发现,每次首页登录的时候都要停顿几十秒. 于是,在程序启动后 ...
- nginx之配置
1)反向代理(Reverse Proxy)方式是指以代理服务器来接受internet上的连接请求,然后将请求转发给内部网络上的服务器,并将从服务器上得到的结果返回给internet上请求连接的客户端, ...
- maven入门--part2 安装
Maven安装和配置 (1)下载安装文件apache-maven-3.03-bin.tar (2)解压至安装目录,安装完毕 (3)修改.bash_profile,修改maven安装路径,修改构建GC配 ...
- 密码基础知识(2)以RSA为例说明加密、解密、签名、验签
密码基础知识(1)https://www.cnblogs.com/xdyixia/p/11528572.html 一.RSA加密简介 RSA加密是一种非对称加密.是由一对密钥来进行加解密的过程,分别称 ...
- Delphi 10.3.2来了!
昨晚,官方正式发布了Delphi 10.3.2,增加对Mac 64应用的开发,支持Linux桌面开发,这个是通过集成fmxlinux实现的,同时修正400个bug,编译器,102个ide,84个fmx ...
- 怎么处理Win7电脑打开软件速度慢的情况?
很多使用Win7系统的用户都会发现这么一个问题,就是电脑在使用过一段时间后,打开一个应用软件的速度就会变慢,非常耽误时间.下面就和大家分享一个解决Win7系统应用软件打开速度慢的小技巧. Win7系统 ...
- c3p0的错误mchange.v2.ser.Indirector
mchange-commons-java-0.2.11.jar 没有会报错 (java.lang.NoClassDefFoundError:com.mchange.v2.ser.Indirec ...