当前位置:网站首页>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;
}
边栏推荐
- [牛客网刷题 Day6] JZ27 二叉树的镜像
- gym安装踩坑记录
- 施努卡:机器视觉定位技术 机器视觉定位原理
- 优雅的 Controller 层代码
- 嵌入式工程师如何提高工作效率
- ThreadLocal会用可不够
- 原型与原型链
- Five simple and practical daily development functions of chrome are explained in detail. Unlock quickly to improve your efficiency!
- Study summary of postgraduate entrance examination in July
- Deeply analyze the main contents of erc-4907 agreement and think about the significance of this agreement to NFT market liquidity!
猜你喜欢

对存储过程进行加密和解密(SQL 2008/SQL 2012)

MONAI版本更新到 0.9 啦,看看有什么新功能

mysql插入数据创建触发器填充uuid字段值

Socket communication principle and Practice

XML configuration file parsing and modeling

多线程-异步编排

Some properties of leetcode139 Yang Hui triangle

Use the fetch statement to obtain the repetition of the last row of cursor data
![[STM32] solution to the problem that SWD cannot recognize devices after STM32 burning program](/img/03/41bb3870b9a6c2ee66099abac08eb3.png)
[STM32] solution to the problem that SWD cannot recognize devices after STM32 burning program

Elegant controller layer code
随机推荐
[dai6] mirror image of JZ27 binary tree
2022.7.6DAY598
【HigherHRNet】 HigherHRNet 详解之 HigherHRNet的热图回归代码
IO model review
关于easyflash v3.3使用过程的记录
The Hal library is configured with a general timer Tim to trigger ADC sampling, and then DMA is moved to the memory space.
Prototype and prototype chain
Leetcode-560: subarray with sum K
1321:【例6.3】删数问题(Noip1994)
How embedded engineers improve work efficiency
STM32 ADC and DMA
JS实现链式调用
【华为机试真题详解】高矮个子排队
PDF文档签名指南
那些易混淆的概念(三):function和class
深入理解Apache Hudi异步索引机制
[daiy5] jz77 print binary tree in zigzag order
Learning records - high precision addition and multiplication
求方程ax^2+bx+c=0的根(C语言)
Kotlin realizes wechat interface switching (fragment exercise)