当前位置:网站首页>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;
}
边栏推荐
- 对存储过程进行加密和解密(SQL 2008/SQL 2012)
- . Net configuration system
- Appx code signing Guide
- IPv4套接字地址结构
- Google colab loads Google drive (Google drive is used in Google colab)
- When there are pointer variable members in the custom type, the return value and parameters of the assignment operator overload must be reference types
- Postman interface test II
- 搭建物联网硬件通信技术几种方案
- Review of the losers in the postgraduate entrance examination
- 2022.7.4DAY596
猜你喜欢

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

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

Leetcode exercise - 113 Path sum II

A wave of open source notebooks is coming

LeetCode 练习——113. 路径总和 II

Es classes and objects, prototypes

Use of JSON extractor originals in JMeter

Several schemes of building hardware communication technology of Internet of things
![[learning notes - Li Hongyi] Gan (generation of confrontation network) full series (I)](/img/94/b4df1ce2861a851fcd8de3e08540b0.png)
[learning notes - Li Hongyi] Gan (generation of confrontation network) full series (I)

JMeter loop controller and CSV data file settings are used together
随机推荐
Finally, there is no need to change a line of code! Shardingsphere native driver comes out
HDU-2196 树形DP学习笔记
Chris Lattner, père de llvm: Pourquoi reconstruire le logiciel d'infrastructure ai
STM32产品介绍
ArcGIS operation: converting DWG data to SHP data
Fiddler simulates the interface test
Appx代码签名指南
ArcGIS operation: batch modify attribute table
Some properties of leetcode139 Yang Hui triangle
IO模型复习
ORM -- grouping query, aggregation query, query set queryset object properties
Programming features of ISP, IAP, ICP, JTAG and SWD
Wallys/IPQ6010 (IPQ6018 FAMILY) EMBEDDED BOARD WITH ON-BOARD WIFI DUAL BAND DUAL CONCURRENT
电表远程抄表拉合闸操作命令指令
LLVM之父Chris Lattner:為什麼我們要重建AI基礎設施軟件
ISP、IAP、ICP、JTAG、SWD的编程特点
Google colab loads Google drive (Google drive is used in Google colab)
When there are pointer variable members in the custom type, the return value and parameters of the assignment operator overload must be reference types
Introduction to uboot
IPv4 socket address structure