当前位置:网站首页>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;
}
边栏推荐
- Leetcode-304: two dimensional area and retrieval - matrix immutable
- CC2530 zigbee IAR8.10.1环境搭建
- Several schemes of building hardware communication technology of Internet of things
- A small problem of bit field and symbol expansion
- 5个chrome简单实用的日常开发功能详解,赶快解锁让你提升更多效率!
- ArrayList线程不安全和解决方案
- 2022.7.4DAY596
- openinstall与虎扑达成合作,挖掘体育文化产业数据价值
- 使用 load_decathlon_datalist (MONAI)快速加载JSON数据
- 那些易混淆的概念(三):function和class
猜你喜欢

String formatting

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

BUUCTF---Reverse---reverse1

Encrypt and decrypt stored procedures (SQL 2008/sql 2012)

使用U2-Net深层网络实现——证件照生成程序

优雅的 Controller 层代码

Experience sharing of software designers preparing for exams

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

电表远程抄表拉合闸操作命令指令

XML configuration file parsing and modeling
随机推荐
[牛客网刷题 Day6] JZ27 二叉树的镜像
Using U2 net deep network to realize -- certificate photo generation program
成为优秀的TS体操高手 之 TS 类型体操前置知识储备
5个chrome简单实用的日常开发功能详解,赶快解锁让你提升更多效率!
BigDecimal数值比较
Appx code signing Guide
2022.7.4DAY596
反射效率为什么低?
Hdu-2196 tree DP learning notes
南航 PA3.1
IIC Basics
【STM32】STM32烧录程序后SWD无法识别器件的问题解决方法
Study summary of postgraduate entrance examination in November
High number_ Chapter 1 space analytic geometry and vector algebra_ Quantity product of vectors
HDU-2196 树形DP学习笔记
Multithreaded asynchronous orchestration
串口通讯继电器-modbus通信上位机调试软件工具项目开发案例
1324:【例6.6】整数区间
2022.7.3DAY595
Elegant controller layer code