思路:

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

 #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. echarts中关于自定义legend图例文字

    formatter有两种形式: - 模板 - 回调函数 模板 使用字符串模板,模板变量为图例名称 {name} formatter: 'Legend {name}' 回调函数 formatter: f ...

  2. Visual Studio 2015打开ASP.NET MVC的View提示"Object reference not set to an instance of an object"错误的解决方案

    使用Visual Studio 2013打开没有问题,但Visual Studio 2015打开cshtml就会提示"Object reference not set to an insta ...

  3. Setting up Unicorn with Nginx

    gem install unicorn or gem 'unciron' 1 install Nginx yum install ... 2 Configuration vi /etc/nginx/n ...

  4. Amazon ec2 改成密码登录方式

    sudo passwd rootsu rootvi /etc/ssh/sshd_config"# PasswordAuthentication yes" uncommentsbin ...

  5. DragonBones龙骨换装(局部换装+全局换装)

    参考: Egret官方换装动画 Egret换装三种方式 CSDN(全局换装) egret使用DragonBones实现简单的换装 换装,主要是替换任意插槽的图片,来达到局部换装的目的. 游戏中可以只制 ...

  6. Xcode - LLDB调试技巧

    LLDB是Xcode默认的调试器,它与LLVM编译器一起,带给我们更丰富的流程控制和数据检测的调试功能.平时用Xcode运行程序,实际走的都是LLDB.熟练使用LLDB,可以让你debug事半功倍. ...

  7. Anaconda中配置Pyspark的Spark开发环境

    1.windows下载并安装Anaconda集成环境 URL:https://www.continuum.io/downloads 2.在控制台中测试ipython是否启动正常 3.安装JDK 3.1 ...

  8. 蓝桥杯 - 数字排列(今有7对数字) - [两种不同的DFS思路]

    今有7对数字:两个1,两个2,两个3,...两个7,把它们排成一行.要求,两个1间有1个其它数字,两个2间有2个其它数字,以此类推,两个7之间有7个其它数字.如下就是一个符合要求的排列: 171264 ...

  9. hihocoder 1330 - 数组重排 - [hiho一下167周][最小公倍数]

    题目链接:https://hihocoder.com/problemset/problem/1330 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 小Hi想知道,如果他 ...

  10. AT2043 AND Grid 构造

    正解:构造 解题报告: 传送门传送门! 这题psj讲了俩做法,一个是最常见的解法,还一种还不知道484对的QAQ 然后先把psj讲的不知正确性的做法港下QwQ 大概就是说,第一个图,先把底给染完 然后 ...