思路:

  先二分下界,再二分上届。

 #include <bits/stdc++.h>

 using namespace std;

 #define MP make_pair
#define PB push_back
typedef long long LL;
typedef pair<int,int> PII;
const double eps=1e-;
const double pi=acos(-1.0);
const int K=1e6+;
const int mod=1e9+; struct node
{
int x,y,w,h;
node(){}
node(int a,int b,int c,int d){x=a,y=b,w=c,h=d;}
}rc[K]; LL sum,ls;
LL check(int x,int n)
{
LL ret=;
for(int i=;i<=n;i++)
if(rc[i].x+rc[i].w<=x)
ret+=rc[i].w*1LL*rc[i].h;
else if(rc[i].x<=x)
ret+=1LL*(x-rc[i].x)*rc[i].h;
return ret;
}
int main(void)
{
//freopen("in.acm","r",stdin);
int t;cin>>t;
while(t--)
{
int R,l,r,n,ll,rr;
sum=,ls=1e15;
scanf("%d%d",&R,&n);
for(int i=;i<=n;i++)
scanf("%d%d%d%d",&rc[i].x,&rc[i].y,&rc[i].w,&rc[i].h),sum+=1LL*rc[i].w*rc[i].h;
l=,r=R;
while(l<=r)
{
int mid=l+r>>;
LL ret=check(mid,n);
if(ret>=sum-ret)
ll=mid,r=mid-;
else
l=mid+;
}
ls=2LL*check(ll,n)-sum;
l=ll,r=R;
while(l<=r)
{
int mid=l+r>>;
LL ret=check(mid,n);
if(2LL*ret-sum<=ls)
rr=mid,l=mid+;
else
r=mid-;
}
printf("%d\n",rr);
}
return ;
}

UVALive - 7261 Xiongnu's Land的更多相关文章

  1. UVALive 7261 Xiongnu's Land (扫描线)

    Wei Qing (died 106 BC) was a military general of the Western Han dynasty whose campaigns against the ...

  2. (UVALive 7261)Xiongnu's Land 二分

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

  3. 2015北京区域赛 Xiongnu's Land

    Wei Qing (died 106 BC) was a military general of the Western Han dynasty whose campaigns against the ...

  4. [ An Ac a Day ^_^ ] HihoCoder 1249 Xiongnu's Land 线性扫描

    拿到了icpc北京站的参赛名额 感谢亮哥~ 虽然是地狱之战 但也要全力以赴! 题意: 有一片沙漠 n片绿洲 让你用一条线分成两部分 左≥右 而且分割线要尽量靠右 问线的位置 思路: 网上说可以二分 没 ...

  5. 二分+贪心 hihocoder 1249 Xiongnu's Land (15北京A)

    题目传送门 题意:有多个矩形分布在[0, 0]到[R, R]的的范围内,画一条竖线分割成两块矩形,使得左边包括矩形的面积大于等于右边的面积,在这个前提下使得画的竖线尽量远 分析:二分答案,当面积相等时 ...

  6. 【hihocoder 1249 Xiongnu's Land】线性扫描

    2015区域赛北京赛区的三水,当时在赛场上没做出的原因是复杂度分析不正确导致把方法想复杂了.近来复习复杂度分析,觉得不能只是笼统地看渐进复杂度(big-O),更应根据算法的伪码计算真正的以基本操作数为 ...

  7. hiho1249 Xiongnu's Land

    题目链接:http://hihocoder.com/problemset/problem/1249 题目大意:有一个大正方形里面有好多不重叠的小矩形,怎么找出一条竖线分割这个正方形,使得两边的矩形面积 ...

  8. UVALive - 4108 SKYLINE[线段树]

    UVALive - 4108 SKYLINE Time Limit: 3000MS     64bit IO Format: %lld & %llu Submit Status uDebug ...

  9. UVALive - 3942 Remember the Word[树状数组]

    UVALive - 3942 Remember the Word A potentiometer, or potmeter for short, is an electronic device wit ...

随机推荐

  1. 改变presentModalView大小

    rc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; rc.modalPresentationStyle = UIModalP ...

  2. locate命令的使用

    使用locate命令,遇到了这样的情况:当前目录下有一个文件,而使用这个命令时却查找不到这个文件,上网查了一下,找到了原因,就在下面. 1. find find是最常见和最强大的查找命令,你可以用它找 ...

  3. centos7搭建docker私有仓库

    1.环境: [root@docker02 anchors]# cat /etc/redhat-release CentOS Linux release 7.3.1611 (Core) [root@do ...

  4. freemarker了解

    今天主要了解了项目流程,了解了这周要做退款详情迁移,了解了freemarker

  5. background-size:100% 100% 时 background-position: % 失效

    背景知识: background-size background-position 难题: background-size 为 100% 100% 时,background-position 部分失效 ...

  6. windows远程访问ubuntu下的jupyter notebook必要配置

    0.生成配置文件(一般采用默认) jupyter notebook --generate-config 1.打开ipython, 创建一个密文密码 In [1]: from notebook.auth ...

  7. 扩展KMP算法小记

    参考来自<拓展kmp算法总结>:http://blog.csdn.net/dyx404514/article/details/41831947 扩展KMP解决的问题: 定义母串S和子串T, ...

  8. TCP 123=网络时间协议(NTP),Net Controller

    TCP 123=网络时间协议(NTP),Net Controller

  9. linker command failed with exit code 1 (use -v to see invocation) 变量重名

    有时候,xcode报错看不到,点最后一个按钮,类似气泡的就能看到 报错信息: duplicate symbol _imgNummmm in:    /Users/mianmian/Library/De ...

  10. Tautology---poj3295(枚举判断是否为永真式)

    题目链接:http://poj.org/problem?id=3295 题意:判断是否是永真式,其中 p q r s t 表示逻辑变量其值为0或者1: 枚举所有逻辑变量的值,然后判断是否出现false ...