当前位置:网站首页>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;
}
边栏推荐
- Deeply analyze the main contents of erc-4907 agreement and think about the significance of this agreement to NFT market liquidity!
- 宁愿把简单的问题说一百遍,也不把复杂的问题做一遍
- 5个chrome简单实用的日常开发功能详解,赶快解锁让你提升更多效率!
- How embedded engineers improve work efficiency
- MySQL insert data create trigger fill UUID field value
- Socket通信原理和实践
- .NET配置系统
- 2022.7.6DAY598
- BUUCTF---Reverse---reverse1
- 枪出惊龙,众“锁”周之
猜你喜欢
Application of OpenGL gllightfv function and related knowledge of light source
IIC Basics
[sword finger offer] 42 Stack push in and pop-up sequence
对word2vec的一些浅层理解
Guide de signature du Code Appx
【STM32】STM32烧录程序后SWD无法识别器件的问题解决方法
串口通讯继电器-modbus通信上位机调试软件工具项目开发案例
[牛客网刷题 Day5] JZ77 按之字形顺序打印二叉树
Pre knowledge reserve of TS type gymnastics to become an excellent TS gymnastics master
P1031 [NOIP2002 提高组] 均分纸牌
随机推荐
Several schemes of building hardware communication technology of Internet of things
Mendeley--免费的文献管理工具,给论文自动插入参考文献
JMeter loop controller and CSV data file settings are used together
Leetcode-560: subarray with sum K
深入分析ERC-4907协议的主要内容,思考此协议对NFT市场流动性意义!
【acwing】789. 数的范围(二分基础)
ArrayList线程不安全和解决方案
Some superficial understanding of word2vec
I'd rather say simple problems a hundred times than do complex problems once
IO model review
Talking about the return format in the log, encapsulation format handling, exception handling
南航 PA3.1
@Configuration, use, principle and precautions of transmission:
[牛客网刷题 Day6] JZ27 二叉树的镜像
施努卡:机器人视觉抓取工作原理 机器视觉抓取
电表远程抄表拉合闸操作命令指令
C logging method
Inno Setup 打包及签名指南
gym安装踩坑记录
.NET配置系统