Codeforces 479B. Towers 暴力
纯暴力.....
1 second
256 megabytes
standard input
standard output
As you know, all the kids in Berland love playing with cubes. Little Petya has n towers consisting of cubes of the same size. Tower with number i consists
of ai cubes
stacked one on top of the other. Petya defines the instability of a set of towers as a value equal to the difference between the heights of the highest and the lowest of the towers. For example,
if Petya built five cube towers with heights (8, 3, 2, 6, 3), the instability of this set is equal to 6 (the highest tower has height 8, the lowest one has height 2).
The boy wants the instability of his set of towers to be as low as possible. All he can do is to perform the following operation several times: take the top cube from some tower and put it on top of some other tower of his set. Please note that Petya would
never put the cube on the same tower from which it was removed because he thinks it's a waste of time.
Before going to school, the boy will have time to perform no more than k such operations. Petya does not want to be late for class, so you have to help him
accomplish this task.
The first line contains two space-separated positive integers n and k (1 ≤ n ≤ 100, 1 ≤ k ≤ 1000)
— the number of towers in the given set and the maximum number of operations Petya can perform. The second line contains n space-separated positive integers ai (1 ≤ ai ≤ 104)
— the towers' initial heights.
In the first line print two space-separated non-negative integers s and m (m ≤ k).
The first number is the value of the minimum possible instability that can be obtained after performing at most k operations, the second number is the number
of operations needed for that.
In the next m lines print the description of each operation as two positive integers i and j,
each of them lies within limits from 1 to n. They represent
that Petya took the top cube from the i-th tower and put in on the j-th
one (i ≠ j). Note that in the process of performing operations the heights of some towers can become equal to zero.
If there are multiple correct sequences at which the minimum possible instability is achieved, you are allowed to print any of them.
3 2
5 8 5
0 2
2 1
2 3
3 4
2 2 4
1 1
3 2
5 3
8 3 2 6 3
3 3
1 3
1 2
1 3
In the first sample you need to move the cubes two times, from the second tower to the third one and from the second one to the first one. Then the heights of the towers are all the same and equal to 6.
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector> using namespace std; int n,k; struct TA
{
int x,id;
}ta[200]; bool cmp(TA a,TA b)
{
return a.x<b.x;
} vector<int> ans; int main()
{
scanf("%d%d",&n,&k);
for(int i=1;i<=n;i++)
{
int x;
scanf("%d",&x);
ta[i].x=x; ta[i].id=i;
}
while(k--)
{
sort(ta+1,ta+1+n,cmp);
int diff=ta[n].x-ta[1].x;
if(diff==0) break;
else
{
ta[n].x--; ta[1].x++;
ans.push_back(ta[n].id);
ans.push_back(ta[1].id);
}
}
sort(ta+1,ta+1+n,cmp);
int diff=ta[n].x-ta[1].x;
int sz=ans.size();
printf("%d %d\n",diff,sz/2);
for(int i=0;i<sz;i+=2)
{
printf("%d %d\n",ans[i],ans[i+1]);
}
return 0;
}
Codeforces 479B. Towers 暴力的更多相关文章
- codeforces 479B Towers 解题报告
题目链接:http://codeforces.com/problemset/problem/479/B 题目意思:有 n 座塔,第 i 座塔有 ai 个cubes在上面.规定每一次操作是从最多 cub ...
- Karen and Game CodeForces - 816C (暴力+构造)
On the way to school, Karen became fixated on the puzzle game on her phone! The game is played as fo ...
- Chladni Figure CodeForces - 1162D (暴力,真香啊~)
Chladni Figure CodeForces - 1162D Inaka has a disc, the circumference of which is nn units. The circ ...
- Codeforces 229D Towers
http://codeforces.com/problemset/problem/229/D 题意:有n(1<=n<=5,000)座塔排在一条直线上,从左到右每个塔的高度分别为hi(1&l ...
- Array and Segments (Easy version) CodeForces - 1108E1 (暴力枚举)
The only difference between easy and hard versions is a number of elements in the array. You are giv ...
- CodeForces - 589D(暴力+模拟)
题目链接:http://codeforces.com/problemset/problem/589/D 题目大意:给出n个人行走的开始时刻,开始时间和结束时间,求每个人分别能跟多少人相遇打招呼(每两人 ...
- CodeForces - 589B(暴力)
题目链接:http://codeforces.com/problemset/problem/589/B 题目大意:告诉你n 个矩形,知道矩形的长度和宽度(长和宽可以互换),每个矩形的长度可以剪掉一部分 ...
- CodeForces - 589B(暴力+排序)
Dasha decided to bake a big and tasty layer cake. In order to do that she went shopping and bought n ...
- Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem F (Codeforces 831F) - 数论 - 暴力
题目传送门 传送门I 传送门II 传送门III 题目大意 求一个满足$d\sum_{i = 1}^{n} \left \lceil \frac{a_i}{d} \right \rceil - \sum ...
随机推荐
- 【PostgreSQL-9.6.3】表空间
在PostgreSQL中,表空间实际上是为表指定一个存储目录,这样方便我们把不同的表放在不同的存储介质或者文件系统中.在创建数据库.表.索引时都可以指定表空间. 1. 创建表空间 --表空间目录必须是 ...
- CSS中常用属性之字体属性
1,以下是CSS中常用字体属性: font-family 字体样式 font-size 字体大小 font-size-adjust 为元素规定 ...
- swift 即使不使用oc的动态派发机制也应该借鉴isa类型识别机制
目前的消息派发机制真的很鸡肋. 简直是一堆狗屎. 类型信息中包含所有需要动态派发的函数:这个包含两类:类和protocol: 在编译时,首先搜索动态派发列表: 动态派发列表没有,在搜索静态派发列表: ...
- 认知升级x
写作目的 今天公司组织了一场关于认知升级的培训讲座,请的主管运营和发行的VP大神,收获颇多,亟待消化.这篇文章可以作为自己课后的一个笔记,自己可以反思,进而同步至团队,大家共同成长. 对于机会的认识 ...
- splice用法解析
splice()方法算是最强大的数组方法了,它有很多种用法,主要用于删除指定位置的数组项,在指定的位置插入数组项,在指定位置替换数组项,slpice()方法始终都会返回一个数组,该数组包括从原始数组中 ...
- ERStudio8.0 破解版 下载
下面地址亲测有效 https://blog.csdn.net/weixin_37139761/article/details/83856069
- 文件描述符 文件操作 <> open 文件句柄
#! /usr/bin/perl use strict;use warnings; =head1print "\n---------------------------------test_ ...
- QT5:先导篇 正则表达式
一.简介 使用正则表达式可以快速完成处理字符串的一些操作,如验证 查找 替换和分割 Qt的QRegExp类是正则表达式的表示类,它基于Perl的正则表达式语言 正则表达式由表达式(expression ...
- vue 改变插值方法
Vue默认的插值是双大括号{{}}.但有时我们会有需求更改这个插值的形式. delimiters:['${','}'] //必须要用一个数组来接收,用逗号隔开.
- MySQL-----连表
连表: **拿到两张表的信息** select * from userinfo,department 弊端是数据会乱,出现重复,不建议这样. **使userinfo表的part_id列与departm ...