当前位置:网站首页>P1031 [NOIP2002 提高组] 均分纸牌
P1031 [NOIP2002 提高组] 均分纸牌
2022-07-07 08:14:00 【暴揍键盘的程序猿】
P1031 [NOIP2002 提高组] 均分纸牌
# [NOIP2002 提高组] 均分纸牌
## 题目描述
有$N$堆纸牌,编号分别为 $1,2,…,N$。每堆上有若干张,但纸牌总数必为 $N$ 的倍数。可以在任一堆上取若干张纸牌,然后移动。
移牌规则为:在编号为 $1$ 堆上取的纸牌,只能移到编号为 $2$ 的堆上;在编号为 $N$ 的堆上取的纸牌,只能移到编号为 $N-1$ 的堆上;其他堆上取的纸牌,可以移到相邻左边或右边的堆上。
现在要求找出一种移动方法,用最少的移动次数使每堆上纸牌数都一样多。
例如 $N=4$ 时,$4$ 堆纸牌数分别为 $9,8,17,6$。
移动 $3$ 次可达到目的:
- 从第三堆取 $4$ 张牌放到第四堆,此时每堆纸牌数分别为 $9,8,13,10$。
- 从第三堆取 $3$ 张牌放到第二堆,此时每堆纸牌数分别为 $9,11,10,10$。
- 从第二堆取 $1$ 张牌放到第一堆,此时每堆纸牌数分别为 $10,10,10,10$。
## 输入格式
第一行共一个整数 $N$,表示纸牌堆数。
第二行共 $N$ 个整数 $A_1,A_2,\cdots,A_N$,表示每堆纸牌初始时的纸牌数。
## 输出格式
共一行,即所有堆均达到相等时的最少移动次数。
## 样例 #1
### 样例输入 #1
```
4
9 8 17 6
```
### 样例输出 #1
```
3
```
## 提示
对于 $100\%$ 的数据,$1 \le N \le 100$,$1 \le A_i \le 10000$。
**【题目来源】**
NOIP 2002 提高组第一题
【AC代码】
#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;
}
边栏推荐
- ISP、IAP、ICP、JTAG、SWD的编程特点
- LLVM之父Chris Lattner:為什麼我們要重建AI基礎設施軟件
- STM32 ADC和DMA
- STM32 product introduction
- Serial communication relay Modbus communication host computer debugging software tool project development case
- 每周推荐短视频:L2级有哪些我们日常中经常会用到的功能?
- LLVM之父Chris Lattner:为什么我们要重建AI基础设施软件
- STM32基础知识—内存映射
- Fiddler simulates the interface test
- Guid primary key
猜你喜欢

Video based full link Intelligent Cloud? This article explains in detail what Alibaba cloud video cloud "intelligent media production" is

Postman interface test I

ORM -- grouping query, aggregation query, query set queryset object properties

ES6中的原型对象

Postman interface test V

Inno Setup 打包及签名指南

Fiddler simulates the interface test

Programming features of ISP, IAP, ICP, JTAG and SWD

Appx代码签名指南

基于gis三维可视化技术的智慧城市建设
随机推荐
Use of JSON extractor originals in JMeter
PDF文档签名指南
2022.7.6DAY598
Serial communication relay Modbus communication host computer debugging software tool project development case
Encrypt and decrypt stored procedures (SQL 2008/sql 2012)
Postman interface test I
求方程ax^2+bx+c=0的根(C语言)
Kotlin实现微信界面切换(Fragment练习)
01 use function to approximate cosine function (15 points)
This article explains the complex relationship between MCU, arm, muc, DSP, FPGA and embedded system
虚数j的物理意义
Inno setup packaging and signing Guide
Use the fetch statement to obtain the repetition of the last row of cursor data
table宽度比tbody宽度大4px
Some thoughts on the testing work in the process of R & D
Postman interface test IV
STM32 ADC and DMA
电表远程抄表拉合闸操作命令指令
[ORM framework]
JMeter loop controller and CSV data file settings are used together