博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Move Cards HUST
阅读量:7281 次
发布时间:2019-06-30

本文共 1764 字,大约阅读时间需要 5 分钟。

 

Description

The Problem

There are N piles of cards, and these piles are numbered as 1,2,...,N respectively. Each pile has some cards, while the total of all cards must be a multiple of N. The player can take some cards from one pile and then put them on another pile as one step.

The follow is the rules: the cards on the pile numbered 1 can only be moved to the pile 2; the cards on the pile N can only be moved to the pile N-1; the cards on other piles, numbered from 2 to N-1, can be moved to either their left pile or right one.

Now the player should move these cards to make the card numbers of each pile equal by minimum steps.

For example: there are 4 piles, and the card numbers of each pile are 9 8 17 6 respectively. So it needs 3 steps to achieve the goal at least.

The Input

The input file consists of one or more test cases. The first line of input is the number of cases. Each case contains 2 lines: the first line of each case contains the only number N indicating the number of piles, and the second line contains a group of integers separated by space, indicating the card numbers of each pile respectively.

The Output

The minimum steps to make all piles' card numbers equal.

 

Sample input

149 8 17 6

Sample output

3 水题一道 附上题目链接
1 #include
2 #include
3 using namespace std; 4 int main (){ 5 int cases; 6 cin>>cases; 7 int add , count; 8 int average , N; 9 while ( cases-- )10 {11 average=count=add=0;12 cin>>N;13 vector
pile (N);14 for ( int i=0; i
>pile[i];17 average += pile[i];18 }19 average/=N;20 for ( int j=0; j

 

 

转载于:https://www.cnblogs.com/neverchanje/p/3464184.html

你可能感兴趣的文章
二维vector基本使用
查看>>
节省微博互粉时间,使用全自动"一键关注"Chrome扩展程序
查看>>
iOS Getter 和Setter 注册xibcell
查看>>
安装Python的numpy库
查看>>
Linux系列:Ubuntu虚拟机设置固定IP上网(配置IP、网关、DNS、防止resolv.conf被重写)...
查看>>
一场么有高端起来的改版~
查看>>
UI之UIImageView--属性及用法
查看>>
linux之SQL语句简明教程---COUNT
查看>>
BZOJ 2005 [Noi2010]能量採集 (容斥)
查看>>
Markov Decision Process
查看>>
实验四主存空间的分配和回收
查看>>
macOS清空字体缓存
查看>>
linux中切换用户方式su和su -的区别
查看>>
php面向对象
查看>>
CHIL-SQL-IN 操作符
查看>>
des 加密 iOS
查看>>
XML 对xml文件的crud的增加 create操作 增加元素 增加属性
查看>>
java TCP通信 socket 套接字 用图片上传轰炸服务器
查看>>
linux处理闰秒
查看>>
Python模块configparser(操作配置文件ini)
查看>>