CF 1042 A Benches —— 二分答案(水题)
题目:http://codeforces.com/problemset/problem/1042/A
代码如下:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define mid ((l+r)>>1)
using namespace std;
int const maxn=;
int n,m,a[maxn],ans,mx;
bool ck(int x)
{
int ret=;
for(int i=;i<=n;i++)ret+=x-a[i];
return (ret>=m);
}
int main()
{
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++)scanf("%d",&a[i]),mx=max(mx,a[i]);
int l=mx,r=mx+m;
while(l<=r)
{
if(ck(mid))ans=mid,r=mid-;
else l=mid+;
}
printf("%d %d\n",ans,mx+m);
return ;
}
CF 1042 A Benches —— 二分答案(水题)的更多相关文章
- Codeforces Round #402 (Div. 2) D. String Game(二分答案水题)
D. String Game time limit per test 2 seconds memory limit per test 512 megabytes input standard inpu ...
- CF 1042A Benches——二分答案(水题)
题目:http://codeforces.com/problemset/problem/1042/A #include<iostream> #include<cstdio> # ...
- AT2165 Median Pyramid Hard 二分答案 脑洞题
无论再来多少次也不可能想到的写法. 二分一个最小的顶端值\(k\),大于设为\(1\)小于等于设为\(0\),可以证猜出来(你跟我说这可以?)如果存在两个连在一起的0/1那么它们会一直往上跑,还可以很 ...
- CF 332A Down the Hatch! 超级水题。。不过题目太长了
A. Down the Hatch! time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- CF 949 D Curfew —— 二分答案
题目:http://codeforces.com/contest/949/problem/D 先二分一个答案,让两边都至少满足这个答案: 由于越靠中间的房间越容易满足(被检查的时间靠后),所以策略就是 ...
- UVa 11636 - Hello World! 二分,水题 难度: 0
题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...
- CF 1008B Turn the Rectangles(水题+贪心)
There are n rectangles in a row. You can either turn each rectangle by 90 degrees or leave it as it ...
- BZOJ 4590 [Shoi2015]自动刷题机 ——二分答案
二分答案水题. #include <cstdio> #include <cstring> #include <iostream> #include <algo ...
- Luogu P2920 时间管理【二分答案】
二分答案水题. (像我这么蒻的人都能十几分钟A掉) https://www.luogu.org/problemnew/show/P2920 开始时间一定在从0到min(t[i]-s[i])的一段区间上 ...
随机推荐
- zabbix源码安装后,设置为服务启动和关闭
zabbix源码安装,使用service启动与关闭服务 1. zabbix客户端的系统服务脚本 1.1 拷贝启动脚本 zabbix的源码提供了系统服务脚本,在/usr/local/src/zabbix ...
- asp.net:Parser Error & HTTP 错误 500.21 - Internal Server Error
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABEcAAAF8CAIAAACiwUIQAAAgAElEQVR4nO2dyZHzOpZGaVEaADNkBB ...
- (蓝桥杯)2018JAVA B组 日志分析
日志统计 小明维护着一个程序员论坛.现在他收集了一份"点赞"日志,日志共有N行.其中每一行的格式是: ts id 表示在ts时刻编号id的帖子收到一个"赞". ...
- 原生JS版和jQuery 版实现文件上传功能
<!doctype html> <html lang="zh"> <head> <meta charset="utf-8&quo ...
- PS一些技巧
色阶的解决办法 我们做效果图的时候经常会使用大面积渐变,时常会出现比较严重的色阶问题,通常出现这些明显色阶的时候,可以通过使用高斯模糊对色阶进行模糊化处理. 在使用PS CC的过程中,笔者经常遇到假死 ...
- 【Codeforces 329B】Biridian Forest
[链接] 我是链接,点我呀:) [题意] 题意 [题解] 找到出口到每个点的最短距离. 设你到出口的最短距离为temp 那么如果某个人到终点的距离<=temp,则他们肯定能遇到你 因为他们可以在 ...
- [NOIP2005] 普及组 循环
陶陶摘苹果 校门外的树 采药 以上三道都不是重点 循环 题目描述 乐乐是一个聪明而又勤奋好学的孩子.他总喜欢探求事物的规律.一天,他突然对数的正整数次幂产生了兴趣. 众所周知,2的正整数次幂最后一位数 ...
- hdu_1398_Square Coins_201404260953
Square Coins Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tota ...
- P1614 爱与愁的心痛
洛谷——P1614 爱与愁的心痛 题目背景 (本道题目隐藏了两首歌名,找找看哪~~~) <爱与愁的故事第一弹·heartache>第一章 <我为歌狂>当中伍思凯神曲<舞月 ...
- 动态替换logback FileAppender/RollingFileAppender 配置- Programmatically configure logback FileAppender/RollingBackAppender
一.本文实际解决的问题 如何在代码中修改logback的RollingFileAppender配置(本文代码实例为修改日志文件路径) 二.针对的场景: 本文解决的问题属于一个大需求的一部分,需求为:需 ...