Atcoder4105 Same Integers(模拟)
https://abc093.contest.atcoder.jp/tasks/arc094_a?lang=en
思路题还是不太会做哈。感觉数据不大,一开始dfs做但是发现不是最优解,一想确实是这么一回事,然后转bfs,但是测第三组数据的时候就能看出来超时了。
其实这题仔细想想,只有两种情况最小值+2,一是大、中值相等时,如果最小值+2可以达到全部相等,或者比另两个大1然后另两个各+1;二是大值比小值大超过1,最后会达到一所说的局面。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<queue>
#define IO ios::sync_with_stdio(false);cin.tie(0);
const int MOD=1e9+;
typedef long long ll;
using namespace std;
int a[], cnt=;
int main()
{
for(int i = ; i < ; i++){
cin >> a[i];
}
sort(a, a+);
while(a[] != a[]){
cnt++;
if(a[] == a[] || a[]-a[]>)
a[] += ;
else a[]++, a[]++;
sort(a, a+);
}
cout << cnt << endl;
return ;
}
Atcoder4105 Same Integers(模拟)的更多相关文章
- Codeforces Educational Codeforces Round 5 A. Comparing Two Long Integers 高精度比大小,模拟
A. Comparing Two Long Integers 题目连接: http://www.codeforces.com/contest/616/problem/A Description You ...
- [LeetCode] 数学计算模拟类问题:加法,除法和幂,注意越界问题。题 剑指Offer,Pow(x, n) ,Divide Two Integers
引言 数学计算的模拟类题目,往往是要求实现某种计算(比如两数相除),实现的过程中会有所限定,比如不允许乘法等等. 这类题目首先要注意计算过程中本身的特殊情况.比如求相除,则必须首先反映过来除数不能为0 ...
- HDOJ 2317. Nasty Hacks 模拟水题
Nasty Hacks Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tota ...
- Codeforces Round #379 (Div. 2) A B C D 水 二分 模拟
A. Anton and Danik time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- Codeforces Round #284 (Div. 2)A B C 模拟 数学
A. Watching a movie time limit per test 1 second memory limit per test 256 megabytes input standard ...
- coderforces #387 Servers(模拟)
Servers time limit per test 2 seconds memory limit per test 256 megabytes input standard input outpu ...
- Codeforces 740A. Alyona and copybooks 模拟
A. Alyona and copybooks time limit per test: 1 second memory limit per test: 256 megabytes input: st ...
- Codeforces 738D. Sea Battle 模拟
D. Sea Battle time limit per test: 1 second memory limit per test :256 megabytes input: standard inp ...
- [ACM_模拟] POJ1068 Parencodings (两种括号编码转化 规律 模拟)
Description Let S = s1 s2...s2n be a well-formed string of parentheses. S can be encoded in two diff ...
随机推荐
- Flink--基于mysql的sink和source
基于mysql的source操作 object MysqlSource { def main(args: Array[String]): Unit = { val env = StreamExecut ...
- 如何查找物理cpu,cpu核心和逻辑cpu的数量
环境 Red Hat Enterprise Linux 4 Red Hat Enterprise Linux 5 Red Hat Enterprise Linux 6 Red Hat Enterpri ...
- eclipse启动web应用 报错
错误:The origin server did not find a current representation for the target resource or is not willing ...
- ELK使用1-Elasticsearch使用
一.es 1.通过curl命令获取es进群信息 a.curl -i(设置协议的头信息) -XGET 'http:192.168.30.41:9200/_count' b.查看集群状态 curl -XG ...
- HDU5117 Fluorescent 期望 计数 状压dp 动态规划
原文链接https://www.cnblogs.com/zhouzhendong/p/HDU5117.html 题目传送门 - HDU5117 题意 $T$ 组数据. 给你 $n$ 盏灯 ,$m$ 个 ...
- Java 之 JQuery
1.JQuery a.定义:jQuery 是一个 JavaScript 库 b.作用:极大地简化了 JavaScript 编程 c.引入: <script src="jquery.js ...
- 牛客练习赛28B (经典)【线段树】
<题目链接> qn姐姐最好了~ qn姐姐给你了一个长度为n的序列还有m次操作让你玩, 1 l r 询问区间[l,r]内的元素和 2 l r 询问区间[l,r]内的元 ...
- Linux 中 Windows 中文乱码
Linux 下 Windows 源代码中文乱码 由于 windows 和 linux 对文本的编码方式不同,所以经常会有 windows 中生成的文本在 linux 中打开乱码的情况. 比如: 我面临 ...
- Maven设置utf8编码格式
在pom.xml添加如下配置即可 <properties> <project.build.sourceEncoding>UTF-8</project.build.sour ...
- 最详细的Vuex教程
什么是Vuex? vuex是一个专门为vue.js设计的集中式状态管理架构.状态?我把它理解为在data中的属性需要共享给其他vue组件使用的部分,就叫做状态.简单的说就是data中需要共用的属性. ...