题目链接:http://hihocoder.com/problemset/problem/1249

题目大意:有一个大正方形里面有好多不重叠的小矩形,怎么找出一条竖线分割这个正方形,使得两边的矩形面积尽量相等并且正方形左边的面积比右边大

思路:做两次二分就好了

 #include <stdio.h>
#include <iostream>
#include <algorithm>
using namespace std;
#define xx first
#define yy second
struct node{
int len,wid;
long long sum;
pair<int,int> p1;
pair<int,int> p2;
void cal(){
p2.xx=p1.xx+len;
p2.yy=p1.yy-wid;
sum=(long long)len*wid;
}
};
bool cmp(const node&a,const node&b){
return a.p1.xx<b.p1.xx;
}
const int maxn=1e4+;
node a[maxn];
int n,r;
long long check(int x){
long long tmp=;
for(int i=;i<=n;i++){
tmp+=((long long )a[i].wid*max(min(a[i].len,x-a[i].p1.xx),));
}
return tmp;
}
int binary_search(int R,long long sum){
int l=-,r=R+;
int mid;
while(r-l>){
mid=(l+r)>>;
long long tmp=check(mid);
if(tmp>=sum-tmp){
r=mid;
}
else l=mid;
}
long long ans=check(r);
l=-,r=R+;
while(r-l>){
mid=(l+r)>>;
long long tmp=check(mid);
if(tmp>ans) r=mid;
else l=mid;
}
return l;
}
int main(){
int T;
//freopen("C:\\Users\\acm\\Desktop\\2015Beijing\\in.txt","r",stdin);
scanf("%d",&T);
while(T--){
scanf("%d",&r);
scanf("%d",&n);
long long sum=;
for(int i=;i<=n;i++){
int x,y,len,wid;
scanf("%d %d %d %d",&x,&y,&len,&wid);
sum+=((long long)len*wid);
a[i].len=len,a[i].wid=wid,a[i].p1=make_pair(x,y),a[i].cal();
}
sort(a+,a++n,cmp);
printf("%d\n",binary_search(r,sum));
}
return ;
}

hiho1249 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. 二分+贪心 hihocoder 1249 Xiongnu's Land (15北京A)

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

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

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

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

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

  7. UVALive - 7261 Xiongnu's Land

    思路: 先二分下界,再二分上届. #include <bits/stdc++.h> using namespace std; #define MP make_pair #define PB ...

  8. POJ 1365 Prime Land(数论)

    题目链接: 传送门 Prime Land Time Limit: 1000MS     Memory Limit: 10000K Description Everybody in the Prime ...

  9. [2015hdu多校联赛补题]hdu5378 Leader in Tree Land

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5378 题意:给你一棵n个结点的有根树.因为是有根树,那么每个结点可以指定以它为根的子树(后面讨论的子树 ...

随机推荐

  1. 动态规划-LIS最长上升子序列

    优化链接 [https://blog.csdn.net/George__Yu/article/details/75896330] #include<stdio.h> #include< ...

  2. CF892.B. Wrath

    ---恢复内容开始--- 题意: 有n个犯人,手上都有个长度为Li的武器,当铃响时大家同时挥动武器,只能把前面攻击范围内的敌人杀死,问最后还剩几个人. 题目传送门: [http://codeforce ...

  3. Factors of Factorial AtCoder - 2286 (N的阶乘的因子个数)(数论)

    Problem Statement You are given an integer N. Find the number of the positive divisors of N!, modulo ...

  4. vue学习笔记总结----思维导图

  5. react 组件列表

    let data=[ [ '同时入选IMDB250和豆瓣电影250的电影', '带你进入不正常的世界', '用电[影]来祭奠逝去的岁月', '女孩们的故事[电影]', '', '使用 App [找电影 ...

  6. Linux中各个目录作用

    对于linux新手来说,最感到迷惑的问题之一就是文件都存在哪里呢?特别是对于那些从windows转过来的新手来说,linux的目录结构看起来有些奇怪哦.比如没有C盘,没有分盘符,一大堆不知道用途的文件 ...

  7. [转帖]nginx服务器安装及配置文件详解

    nginx服务器安装及配置文件详解 http://seanlook.com/2015/05/17/nginx-install-and-config/  发表于 2015-05-17 |  更新于: 2 ...

  8. 动态SQL3

    Oracle的批量操作 Oracle不支持VALUES(),(),()这种方式,所以不能用上一节所讲的方法. 有时候业务会包含很多次数据库操作,为了减少数据库连接,我们会选择一次提交大量sql, 这时 ...

  9. jquery 设置cookie、删除cookie、获取cookie

    1.引入jquery.js <script src="//cdn.bootcss.com/jquery/1.12.4/jquery.js"></script> ...

  10. @PathVariable

    @PathVariable是用来对指定请求的URL路径里面的变量 eg: Java代码 @RequestMapping(value = "form/{id}/apply", met ...