当前位置:网站首页>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 二叉树的镜像
- 555电路详解
- BUUCTF---Reverse---reverse1
- IIC Basics
- 2022.7.5DAY597
- Leetcode-560: subarray with sum K
- 无法打开内核设备“\\.\VMCIDev\VMX”: 操作成功完成。是否在安装 VMware Workstation 后重新引导? 模块“DevicePowerOn”启动失败。 未能启动虚拟机。
- How embedded engineers improve work efficiency
- gym安装踩坑记录
- JMeter loop controller and CSV data file settings are used together
猜你喜欢

0x0fa23729 (vcruntime140d.dll) (in classes and objects - encapsulation.Exe) exception thrown (resolved)

String formatting

leetcode-560:和为 K 的子数组

Several schemes of building hardware communication technology of Internet of things
![[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

无法打开内核设备“\\.\VMCIDev\VMX”: 操作成功完成。是否在安装 VMware Workstation 后重新引导? 模块“DevicePowerOn”启动失败。 未能启动虚拟机。
![[daiy5] jz77 print binary tree in zigzag order](/img/ba/b2dfbf121798757c7b9fba4811221b.png)
[daiy5] jz77 print binary tree in zigzag order

【二开】【JeecgBoot】修改分页参数

【acwing】786. Number k

【acwing】786. 第k个数
随机推荐
CAS机制
HDU-2196 树形DP学习笔记
1324:【例6.6】整数区间
串口通讯继电器-modbus通信上位机调试软件工具项目开发案例
【剑指Offer】42. 栈的压入、弹出序列
Kotlin实现微信界面切换(Fragment练习)
Kotlin realizes wechat interface switching (fragment exercise)
Leetcode-304: two dimensional area and retrieval - matrix immutable
mysql插入数据创建触发器填充uuid字段值
Socket通信原理和实践
路由器开发知识汇总
使用 load_decathlon_datalist (MONAI)快速加载JSON数据
CC2530 zigbee IAR8.10.1环境搭建
.NET配置系统
1323:【例6.5】活动选择
【实战】霸榜各大医学分割挑战赛的Transformer架构--nnFormer
HAL库配置通用定时器TIM触发ADC采样,然后DMA搬运到内存空间。
The mobile terminal automatically adjusts the page content and font size by setting rem
The width of table is 4PX larger than that of tbody
ArrayList线程不安全和解决方案