当前位置:网站首页>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;
}
边栏推荐
- How to cancel automatic saving of changes in sqlyog database
- Mongodb creates an implicit database as an exercise
- EasyExcel读取写入简单使用
- 学习记录——高精度加法和乘法
- HAL库配置通用定时器TIM触发ADC采样,然后DMA搬运到内存空间。
- 2022.7.6DAY598
- The variables or functions declared in the header file cannot be recognized after importing other people's projects and adding the header file
- 关于hzero-resource报错(groovy.lang.MissingPropertyException: No such property: weight for class)
- Chris LATTNER, the father of llvm: why should we rebuild AI infrastructure software
- Postman tutorial - scripting
猜你喜欢

XML configuration file parsing and modeling

【剑指Offer】42. 栈的压入、弹出序列

XML配置文件解析与建模

High number_ Chapter 1 space analytic geometry and vector algebra_ Quantity product of vectors

基于HPC场景的集群任务调度系统LSF/SGE/Slurm/PBS

Appx代碼簽名指南

Chris LATTNER, the father of llvm: why should we rebuild AI infrastructure software

【acwing】789. 数的范围(二分基础)

虚数j的物理意义

Postman interface test V
随机推荐
Postman interface test II
【华为机试真题详解】高矮个子排队
Sword finger offer 38 Arrangement of strings [no description written]
EasyExcel读取写入简单使用
Study summary of postgraduate entrance examination in September
Learning records - high precision addition and multiplication
【acwing】786. 第k个数
【acwing】789. Range of numbers (binary basis)
Chris Lattner, père de llvm: Pourquoi reconstruire le logiciel d'infrastructure ai
Download Text, pictures and ab packages used by unitywebrequest Foundation
2022.7.6DAY598
IO模型复习
PDF文档签名指南
Weekly recommended short videos: what are the functions of L2 that we often use in daily life?
php \n 换行无法输出
浅谈日志中的返回格式封装格式处理,异常处理
Mongodb creates an implicit database as an exercise
Review of the losers in the postgraduate entrance examination
【acwing】789. 数的范围(二分基础)
Interface test