题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=5273

思路:二分枚举x。

#include <cstdio>
using namespace std;
const int MAXN = ;
typedef long long LL;
struct Rectangle{
int l, t, w, h;
LL area;
}rect[MAXN];
int R, n;
LL sum;
LL getArea(int x)
{
LL ret = ;
for(int i = ; i < n; i++)
{
if(rect[i].l+rect[i].w <= x)
{
ret += rect[i].area;
}
else if(rect[i].l < x)
{
ret += ((LL)(x - rect[i].l) * rect[i].h);
}
}
return ret;
}
int main()
{
int T;
scanf("%d", &T);
while(T--)
{
sum = ;
scanf("%d %d", &R, &n);
for(int i = ; i < n; i++)
{
scanf("%d %d %d %d", &rect[i].l, &rect[i].t, &rect[i].w, &rect[i].h);
rect[i].area = ((LL)rect[i].w * rect[i].h);
sum += rect[i].area;
}
if(sum == )
{
printf("%d\n", R);
continue;
}
//尽可能使x两边的oases的面积之和相等
int left = -, right = R;//求right.将right初始化为可能的答案,left初始化为取不到的数值.
while(right - left > )
{
int mid = (left + right) >> ;
LL sl = getArea(mid);
LL sr = sum - sl;
if(sl >= sr)
{
right = mid;
}
else
{
left = mid;
}
} //尽可能使x靠右
int s = getArea(right);
left = right, right = R+;//求left.将left去初始化为可能的答案,将right初始化为取不到的答案.
while(right - left > )
{
int mid = (left + right) >> ;
if(getArea(mid) <= s)
{
left = mid;
}
else
{
right = mid;
}
}
printf("%d\n", left);
}
return ;
}

二分答案的过程中左右区间的划分问题。大于等于答案的最左值 mid = (left + right) >> 1; 小于等于答案的最右值 mid = (left + right + 1) >> 1;

#include <cstdio>
using namespace std;
const int MAXN = ;
typedef long long LL;
struct Rect{
int l, t, w, h;
}rect[MAXN];
int n, R;
LL sum;
LL getArea(int x)
{
LL area = ;
for(int i = ; i < n; i++)
{
if(rect[i].l + rect[i].w <= x)
{
area += ((LL)rect[i].w * rect[i].h);
}
else if(rect[i].l < x)
{
area += ((LL)rect[i].h * (x - rect[i].l));
}
}
return area;
}
int main()
{
int T;
scanf("%d", &T);
while(T--)
{
sum = ;
scanf("%d %d", &R, &n);
for(int i = ; i < n; i++)
{
scanf("%d %d %d %d", &rect[i].l, &rect[i].t, &rect[i].w, &rect[i].h);
sum += ((LL)rect[i].w * rect[i].h);
} int left = , right = R;
while(right > left)
{
int mid = (left + right) >> ; //求大于等于答案的最左值
LL s1 = getArea(mid);
LL s2 = sum - s1;
if(s1 >= s2)
{
right = mid;
}
else
{
left = mid + ;
}
} LL tag = getArea(right);
left = right, right = R;
while(right > left)
{
int mid = (left + right + ) >> ; //求小于等于答案的最右值
if(getArea(mid) <= tag)
{
left = mid;
}
else
{
right = mid - ;
}
}
printf("%d\n", left);
}
return ;
}

UVALive7261(2015ACM/ICPC北京赛区现场赛A)的更多相关文章

  1. ACM总结——2017ACM-ICPC北京赛区现场赛总结

    现在距离比赛结束已经过了一个多星期了,也是终于有时间写下心得了.回来就是被压着做项目,也是够够的. 这次比赛一样是我和两个学弟(虽然是学弟,但我的实力才是最弱的T_T)一起参加的,成绩的话打铁,算是情 ...

  2. 2014 ACM/ICPC 鞍山赛区现场赛 D&amp;I 解题报告

    鞍山现场赛结束了呢-- 我们出的是D+E+I三道题-- 吾辈AC掉的是D和I两道,趁着还记得.先在这里写一写我写的两道水题D&I的解题报告吧^_^. D题的意思呢是说星云内有一堆排成一条直线的 ...

  3. 2014年亚洲区域赛北京赛区现场赛A,D,H,I,K题解(hdu5112,5115,5119,5220,5122)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud 下午在HDU上打了一下今年北京区域赛的重现,过了5题,看来单挑只能拿拿铜牌,呜呜. ...

  4. HDU 5120 A Curious Matt(2014北京赛区现场赛A题 简单模拟)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5112 解题报告:扫一遍 #include<cstdio> #include<cstr ...

  5. HDU 5120 Intersection(2014北京赛区现场赛I题 计算几何)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5120 解题报告:给你两个完全相同的圆环,要你求这两个圆环相交的部分面积是多少? 题意看了好久没懂.圆环 ...

  6. HDU 4793 Collision (解二元一次方程) -2013 ICPC长沙赛区现场赛

    题目链接 题目大意 :有一个圆硬币半径为r,初始位置为x,y,速度矢量为vx,vy,有一个圆形区域(圆心在原点)半径为R,还有一个圆盘(圆心在原点)半径为Rm (Rm < R),圆盘固定不动,硬 ...

  7. [hdu5113]Black And White2014北京赛区现场赛B题(搜索加剪枝)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Black And White Time Limit: 2000/2000 MS ...

  8. Substrings 第37届ACM/ICPC 杭州赛区现场赛C题(hdu 4455)

    http://acm.hdu.edu.cn/showproblem.php?pid=4455 https://icpcarchive.ecs.baylor.edu/index.php?option=c ...

  9. hdu 4431 第37届ACM/ICPC 天津赛区现场赛A题 枚举

    题意:就是给了13张牌.问增加哪些牌可以胡牌.m是数字,s是条,p是筒,c是数字 胡牌有以下几种情况: 1.一个对子 +  4组 3个相同的牌或者顺子.  只有m.s.p是可以构成顺子的.东西南北这样 ...

随机推荐

  1. CMDB Autoclient思路分析

    1.start.py里的script.run():执行run函数--> 2.script.py run方法--> 3.判断模式MODE(Agent/SSHSALT)-->4.执行cl ...

  2. keras系列︱seq2seq系列相关实现与案例(feedback、peek、attention类型)

    之前在看<Semi-supervised Sequence Learning>这篇文章的时候对seq2seq半监督的方式做文本分类的方式产生了一定兴趣,于是开始简单研究了seq2seq.先 ...

  3. ss-libev 源码解析local篇(3): server_recv_cb之SNI和STAGE_PARSE

    上一篇看到STAGE_HANDSHAKE中的处理,到发出fake reply.这之后会从socks5 request中解析出remote addr and port,即客户端实际想要访问的服务器地址和 ...

  4. MFMailComposeViewController发送邮件

    1.iPhone API已经提供了系统写邮件界面的接口,使用MFMailComposeViewController,用来显示界面. 2.项目中需要添加MessageUi.framework.头文件加入 ...

  5. crm--01

    需求: 将课程名称与班级综合起来 class ClassListConfig(ModelSatrk): # 自定义显示方式 def display_class(self,obj=None,is_hea ...

  6. 2D game engine essentials [to be continued...]

    All 2D Game Engines/Frameworks are trying to solve the same problem(s). Languages don't matter- they ...

  7. 自回归模型(AR )

    2017/7/2 19:24:15 自回归模型(Autoregressive Model,简称 AR 模型)是最常见的平稳时间序列模型之一.接下将介绍 AR 模型的定义.统计性质.建模过程.预测及应用 ...

  8. 十天学会单片机Day6 学会看数据手册 (IIC总线PCF859芯片( A/D D/A)应用)

    1.实际电路 2.引脚图 3.地址 高四位为固定地址1001,A2A1A0可编程地址,通过观察实际电路,可知A2A1A0 为000.最低位为读写为,1为读,0为写. 4.控制字 控制寄存器的高半字节用 ...

  9. spring mvc 思想

    目录 一.前言 二.spring mvc 核心类与接口 三.spring mvc 核心流程图 四.spring mvc DispatcherServlet说明 五.spring mvc 父子上下文的说 ...

  10. BZOJ2824 AHOI2012 铁盘整理 【IDA*】

    BZOJ2824 AHOI2012 铁盘整理 Description 在训练中,一些臂力训练器材是少不了的,小龙在练习的时候发现举重器械上的铁盘放置的非常混乱,并没有按照从轻到重的顺序摆放,这样非常不 ...