Codeforces 758A. Holiday Of Equality 贪心
题目大意:
给定一个长为\(n\)序列,每次操作在一个数上+1,求最小的操作次数使所有的数大小相同.
题解:
对这种题无话可说
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
inline void read(int &x){
x=0;char ch;bool flag = false;
while(ch=getchar(),ch<'!');if(ch == '-') ch=getchar(),flag = true;
while(x=10*x+ch-'0',ch=getchar(),ch>'!');if(flag) x=-x;
}
inline int cat_max(const int &a,const int &b){return a>b ? a:b;}
inline int cat_min(const int &a,const int &b){return a<b ? a:b;}
const int maxn = 128;
int a[maxn];
int main(){
int n;read(n);
int maxx = 0;
for(int i=1;i<=n;++i){
read(a[i]);
maxx = cat_max(maxx,a[i]);
}
int ans = 0;
for(int i=1;i<=n;++i){
ans += maxx - a[i];
}printf("%d",ans);
getchar();getchar();
return 0;
}
拓展:
如果一次操作既可以+1也可以-1.会是什么样.
解答:
一个结论,最终一定都变为中位数。
Codeforces 758A. Holiday Of Equality 贪心的更多相关文章
- Codeforces 758A Holiday Of Equality
题目链接:http://codeforces.com/problemset/problem/758/A A. Holiday Of Equality time limit per test 1 sec ...
- 【codeforces 758A】Holiday Of Equality
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- Codeforces758A Holiday Of Equality 2017-01-20 10:08 48人阅读 评论(0) 收藏
A. Holiday Of Equality time limit per test 1 second memory limit per test 256 megabytes input standa ...
- codeforces Gym 100338E Numbers (贪心,实现)
题目:http://codeforces.com/gym/100338/attachments 贪心,每次枚举10的i次幂,除k后取余数r在用k-r补在10的幂上作为候选答案. #include< ...
- [Codeforces 1214A]Optimal Currency Exchange(贪心)
[Codeforces 1214A]Optimal Currency Exchange(贪心) 题面 题面较长,略 分析 这个A题稍微有点思维难度,比赛的时候被孙了一下 贪心的思路是,我们换面值越小的 ...
- Codeforces 758A:Holiday Of Equality(水题)
http://codeforces.com/problemset/problem/758/A 题意:给出n个值,求这里面每个值都要变成最大的那个数,总共需要加上多少. 思路:找出最大的直接算. #in ...
- codeforces 349B Color the Fence 贪心,思维
1.codeforces 349B Color the Fence 2.链接:http://codeforces.com/problemset/problem/349/B 3.总结: 刷栅栏.1 ...
- Codeforces Gym 100269E Energy Tycoon 贪心
题目链接:http://codeforces.com/gym/100269/attachments 题意: 有长度为n个格子,你有两种操作,1是放一个长度为1的东西上去,2是放一个长度为2的东西上去 ...
- CodeForces 797C Minimal string:贪心+模拟
题目链接:http://codeforces.com/problemset/problem/797/C 题意: 给你一个非空字符串s,空字符串t和u.有两种操作:(1)把s的首字符取出并添加到t的末尾 ...
随机推荐
- g2o 初始化
typedef g2o::BlockSolver< g2o::BlockSolverTraits<,> > Block; // pose 维度为 6, landmark 维度为 ...
- windows下rsync部署安装
windows下rsync部署安装 2012-06-05 12:06:13| 分类: 系统 | 标签:rsync windows |字号 订阅 rsync在windows与windows ...
- ArcMap中使用ArcPy实现Geometry与WKT的相互转换
在Web GIS迅猛发展的今天,使用浏览器来进行交互以其方便性.快捷性被广大用户所推崇,那么在传输格式方面,都已比較简单的JSON或者WKT来解决网络带宽带来的数据压力. 在ArcGIS10.2版本号 ...
- Chrome自带恐龙小游戏的源码研究(七)
在上一篇<Chrome自带恐龙小游戏的源码研究(六)>中研究了恐龙的跳跃过程,这一篇研究恐龙与障碍物之间的碰撞检测. 碰撞盒子 游戏中采用的是矩形(非旋转矩形)碰撞.这类碰撞优点是计算比较 ...
- request 解决中文乱码问题
package request; import java.io.IOException;import javax.servlet.ServletException;import javax.servl ...
- Codeforces 558(C、D、E)总结
558C 题意:给你n个数,可对每一个数进行操作(乘2或者除以2).求最少的操作使得全部的数都相等. 思路 : dp[ t ] 表示全部的数转化到 t 所需的最少操作, vis[ t ] 表示有多少数 ...
- git系列1
git clone支持多种协议,除了HTTP(s)以外,还支持SSH.Git.本地文件协议等,下面是一些例子. $ git clone http[s]://example.com/path/to/re ...
- 13-redis主从复制
一:redis主从复制 (1)配置要求 一台主maste 二台从slave (2)架构图 (3)配置流程 1:分配拷贝2份redis.conf 分别命名为 redis6380.conf redis63 ...
- win本地配置docker环境
先上官网链接:https://docs.docker.com/get-started/part2/#introduction 优质入门教程:http://www.docker.org.cn/book/ ...
- TCP的四种定时器简单记录
TCP管理的4个不同的定时器: 1.重传定时器:用于当希望收到另一端的确认. 2.坚持定时器:使窗口大小信息保持不断流动. 3.保活定时器:检测TCP空闲连接的另一端何时崩溃或重启. 4.2MSL定时 ...