当前位置:网站首页>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;
}
边栏推荐
- 【acwing】786. Number k
- 求方程ax^2+bx+c=0的根(C语言)
- Adb 实用命令(网络包、日志、调优相关)
- AHB bus in stm32_ Apb2 bus_ Apb1 bus what are these
- The variables or functions declared in the header file cannot be recognized after importing other people's projects and adding the header file
- 根据设备信息进行页面跳转至移动端页面或者PC端页面
- Introduction to uboot
- Prototype object in ES6
- JMeter loop controller and CSV data file settings are used together
- Postman interface test IV
猜你喜欢
Postman interface test III
【acwing】789. 数的范围(二分基础)
Enterprise practice | construction of banking operation and maintenance index system under complex business relations
一文讲解单片机、ARM、MUC、DSP、FPGA、嵌入式错综复杂的关系
Pdf document signature Guide
Chris LATTNER, the father of llvm: why should we rebuild AI infrastructure software
JMeter installation
STM32基础知识—内存映射
Chris Lattner, père de llvm: Pourquoi reconstruire le logiciel d'infrastructure ai
字符串格式化
随机推荐
Deconvolution popular detailed analysis and nn Convtranspose2d important parameter interpretation
每周推荐短视频:L2级有哪些我们日常中经常会用到的功能?
ORM -- logical relation and & or; Sort operation, update record operation, delete record operation
IPv4套接字地址结构
This article explains the complex relationship between MCU, arm, muc, DSP, FPGA and embedded system
Some thoughts on the testing work in the process of R & D
Guide de signature du Code Appx
ES6中的原型对象
关于hzero-resource报错(groovy.lang.MissingPropertyException: No such property: weight for class)
SQLyog数据库怎么取消自动保存更改
table宽度比tbody宽度大4px
STM32 ADC和DMA
ES6中的函數進階學習
单片机(MCU)最强科普(万字总结,值得收藏)
【HigherHRNet】 HigherHRNet 详解之 HigherHRNet的热图回归代码
AHB bus in stm32_ Apb2 bus_ Apb1 bus what are these
. Net configuration system
Appx代码签名指南
Weekly recommended short videos: what are the functions of L2 that we often use in daily life?
ArcGIS operation: batch modify attribute table