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 ...
随机推荐
- pycharm创建python模板文件
1.新建一个项目: 2.右键单击项目名称-->选择新建-->编辑模板文件 3.编辑模板文件保存 4.新建文件测试 至此不再重复添加头部信息了
- net core体系-web应用程序-4net core2.0大白话带你入门-6asp.net core配置文件
asp.net core配置文件 读取配置文件 asp.net core使用appsettings.json代替传统.net framework的web.config中的<appSettin ...
- windows搭建RocketMQ服务
写在前面: 1.基于rocketmq 4.2.0版本 2.64位 win10 系统 3.JDK 1.8 (注意,jdk路径一定不要有空格,不然执行相应的cmd命令时会报错) 4.其它需要的软件,mav ...
- Codeforces 1132E (看题解)
感觉这个题挺有意思的, 我们可以将 L = lcm(1, 2, 3, ... , 8) 看作一组. 然后用dp[ i ][ j ]表示到第 i 种物品当前的值为 j 能用L的最大数量. #includ ...
- docker删除名字为none的imgae
docker rmi $(docker images -f "dangling=true" -q)
- Centos7 安装PhantomJS
1.下载地址:http://phantomjs.org/download.html 2.文件名:phantomjs-2.1.1-linux-x86_64.tar.bz2 # 下载好后进行解压(由于 ...
- Java常用API——时间类
前言:Java.util.*工具包中,包含了集合框架,旧集合类,事件模型,日期和时间设施,国际化和其他使用程序类 (字符串.随机数生成器和位数组) 一.日期类Date 1.概述 Date是一个薄包装类 ...
- JavaEE 之 Spring(三)
1.Spring Web MVC a.定义:是一种基于Java的实现了Web MVC设计模式的请求驱动类型的轻量级Web框架,即使用了MVC架构模式的思想,将web层进行职责解耦,基于请求驱动指的就是 ...
- 使用Chrome浏览器设置XX-net的方法
以下介绍使用Chrome浏览器设置XX-net的方法 1.下载并安装谷歌浏览器. 2.打开https://github.com/XX-net/XX-Net/blob/master/code/d ...
- GYM 101755 K.Video Reviews 【贪心】+【二分】
<题目链接> 题目大意: 一家公司想让n个人给他们的产品评论,所以依次去找这n个人,第i个人会评论当且仅当已经有ai个人评论或他确实对这个产品感兴趣,但是这n个人都不对这个产品感兴趣,问这 ...