当前位置:网站首页>P1031 [noip2002 improvement group] average Solitaire
P1031 [noip2002 improvement group] average Solitaire
2022-07-07 10:32:00 【A program ape who beats the keyboard violently】
P1031 [NOIP2002 Improvement group ] Divide the cards equally
# [NOIP2002 Improvement group ] Divide the cards equally
## Title Description
Yes $N$ Pile up cards , The numbers are $1,2,…,N$. There are several sheets on each pile , But the total number of cards must be $N$ Multiple . You can take several cards from any pile , And then move .
The transfer rule is : At No $1$ Cards from the pile , Can only be moved to the number of $2$ On the pile of ; At No $N$ A deck of cards , Can only be moved to the number of $N-1$ On the pile of ; Other cards from the pile , It can be moved to the adjacent left or right pile .
Now we need to find a way to move , Make the same number of cards on each stack with the least number of moves .
for example $N=4$ when ,$4$ The number of cards in the pile is $9,8,17,6$.
Move $3$ Once attainable goal :
- Take from the third pile $4$ Put cards in the fourth pile , At this time, the number of cards in each stack is $9,8,13,10$.
- Take from the third pile $3$ Put cards in the second pile , At this time, the number of cards in each stack is $9,11,10,10$.
- From the second stack $1$ Put cards in the first pile , At this time, the number of cards in each stack is $10,10,10,10$.
## Input format
The first line is an integer $N$, Indicates the number of stacks of cards .
The second line is $N$ It's an integer $A_1,A_2,\cdots,A_N$, Indicates the number of cards at the beginning of each stack .
## Output format
All in one line , That is, the minimum number of moves when all heaps are equal .
## Examples #1
### The sample input #1
```
4
9 8 17 6
```
### Sample output #1
```
3
```
## Tips
about $100\%$ The data of ,$1 \le N \le 100$,$1 \le A_i \le 10000$.
**【 Title source 】**
NOIP 2002 Improve the first question of the group
【AC Code 】
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iomanip>
#include<iostream>
#include<string>
using namespace std;
typedef long long LL;
const int INF=0x3f3f3f3f;
const int N=110;
const double eps=1e-5;
int read()
{
char ch=getchar();
int x=0,f=1;
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+ch-48,ch=getchar();}
return x*f;
}
int n,a[N],avr,ans;
int main()
{
n=read();
for(int i=1;i<=n;i++)
{
a[i]=read();
avr+=a[i];
}
avr/=n;
for(int i=1;i<=n;i++)
if(a[i]-avr)
{
a[i+1]+=a[i]-avr;
ans++;
}
printf("%d",ans);
return 0;
}
边栏推荐
- Experience sharing of software designers preparing for exams
- Learning records - high precision addition and multiplication
- Inno setup packaging and signing Guide
- Adb 实用命令(网络包、日志、调优相关)
- 2022.7.3DAY595
- 对存储过程进行加密和解密(SQL 2008/SQL 2012)
- 555电路详解
- 2022.7.6DAY598
- 深入分析ERC-4907协议的主要内容,思考此协议对NFT市场流动性意义!
- @Transcation的配置,使用,原理注意事项:
猜你喜欢
leetcode-304:二维区域和检索 - 矩阵不可变
Inno Setup 打包及签名指南
01 use function to approximate cosine function (15 points)
基于HPC场景的集群任务调度系统LSF/SGE/Slurm/PBS
Trajectory planning for multi-robot systems: Methods and applications 综述阅读笔记
1323:【例6.5】活动选择
Deeply analyze the main contents of erc-4907 agreement and think about the significance of this agreement to NFT market liquidity!
多线程-异步编排
【剑指Offer】42. 栈的压入、弹出序列
P1223 排队接水/1319:【例6.1】排队接水
随机推荐
555 circuit details
PDF文档签名指南
Prototype object in ES6
2022.7.5DAY597
CC2530 ZigBee iar8.10.1 environment construction
Leetcode-304: two dimensional area and retrieval - matrix immutable
When there are pointer variable members in the custom type, the return value and parameters of the assignment operator overload must be reference types
Prototype and prototype chain
P1223 排队接水/1319:【例6.1】排队接水
Yarn的基础介绍以及job的提交流程
【acwing】786. 第k个数
无法打开内核设备“\\.\VMCIDev\VMX”: 操作成功完成。是否在安装 VMware Workstation 后重新引导? 模块“DevicePowerOn”启动失败。 未能启动虚拟机。
[higherhrnet] higherhrnet detailed heat map regression code of higherhrnet
Study summary of postgraduate entrance examination in October
HDU-2196 树形DP学习笔记
Socket communication principle and Practice
Experience sharing of software designers preparing for exams
@Transcation的配置,使用,原理注意事项:
Study summary of postgraduate entrance examination in September
Remote meter reading, switching on and off operation command