题目链接: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. Stack Sorting CodeForces - 911E (思维+单调栈思想)

    Let's suppose you have an array a, a stack s (initially empty) and an array b (also initially empty) ...

  2. mysql数据的导入和导出

    一. mysqldump工具基本用法,不适用于大数据备份   1. 备份所有数据库: mysqldump -u root -p --all-databases > all_database_sq ...

  3. elasticSearch聚合sum查询

    有时需要统计一段时间内,订单的总金额.类似于sql的sum,针对某一字段求和.这就涉及到es的聚合查询,来看看用spring-data-elasticSearch怎么写:   QueryBuilder ...

  4. c#+linux+mono+Redis集群(解决无法连接Redis的问题)

    在linux环境中使用mono来执行c#的程序, 在连接redis的时候遇到了无法连接数据库的错误.如下: Unhandled Exception:StackExchange.Redis.RedisC ...

  5. vue处理异步数据踩过的坑

    在开发时,由于数据是异步的导致页面在render 时data是空值 出现报错和警告. 我是这么处理的 把data先写出一个空的完整结构.暂时是这么处理 或者用三元表达式进行赋值监听.data ?myd ...

  6. node错误中间件处理 express类 带有路由操作

    let express = require('express'); let app = new express(); let bodyParser = require('body-parser'); ...

  7. opencv2\flann\matrix.h(69): error C2059: 语法错误:“,”

    在提示错误的matrix.h头文件中,修改一下,在free前加上_ ,即FLANN_DEPRECATED void _free() .

  8. 使用 idea 产生错误The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized

    解决方法 spring.datasource.url=jdbc:mysql://localhost:3306/spring_cache?serverTimezone=GMT%2B8

  9. PDO连接mysql数据库加载慢

    今天在使用PDO连接mysql操作数据库的时候,发现速度特别慢,都1~2s的时间,不知道怎么回事,后来一步一步排除到new PDO 导致过慢的原因, 这个尴尬了...,调试了半天都没想到问下度娘,才知 ...

  10. umask 文件默认权限

    参考资料 http://book.51cto.com/art/200709/57189.htm umask就是指定当前用户在建立文件或目录时候的属性默认值. linux-xdYUnA:~ # umas ...