hiho1249 Xiongnu's Land
题目链接: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的更多相关文章
- UVALive 7261 Xiongnu's Land (扫描线)
Wei Qing (died 106 BC) was a military general of the Western Han dynasty whose campaigns against the ...
- (UVALive 7261)Xiongnu's Land 二分
题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...
- 2015北京区域赛 Xiongnu's Land
Wei Qing (died 106 BC) was a military general of the Western Han dynasty whose campaigns against the ...
- 二分+贪心 hihocoder 1249 Xiongnu's Land (15北京A)
题目传送门 题意:有多个矩形分布在[0, 0]到[R, R]的的范围内,画一条竖线分割成两块矩形,使得左边包括矩形的面积大于等于右边的面积,在这个前提下使得画的竖线尽量远 分析:二分答案,当面积相等时 ...
- 【hihocoder 1249 Xiongnu's Land】线性扫描
2015区域赛北京赛区的三水,当时在赛场上没做出的原因是复杂度分析不正确导致把方法想复杂了.近来复习复杂度分析,觉得不能只是笼统地看渐进复杂度(big-O),更应根据算法的伪码计算真正的以基本操作数为 ...
- [ An Ac a Day ^_^ ] HihoCoder 1249 Xiongnu's Land 线性扫描
拿到了icpc北京站的参赛名额 感谢亮哥~ 虽然是地狱之战 但也要全力以赴! 题意: 有一片沙漠 n片绿洲 让你用一条线分成两部分 左≥右 而且分割线要尽量靠右 问线的位置 思路: 网上说可以二分 没 ...
- UVALive - 7261 Xiongnu's Land
思路: 先二分下界,再二分上届. #include <bits/stdc++.h> using namespace std; #define MP make_pair #define PB ...
- POJ 1365 Prime Land(数论)
题目链接: 传送门 Prime Land Time Limit: 1000MS Memory Limit: 10000K Description Everybody in the Prime ...
- [2015hdu多校联赛补题]hdu5378 Leader in Tree Land
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5378 题意:给你一棵n个结点的有根树.因为是有根树,那么每个结点可以指定以它为根的子树(后面讨论的子树 ...
随机推荐
- H5 37-背景缩写
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Minesweeper
你玩过扫雷吗?这个可爱的小游戏带有一个我们记不住名字的操作系统.游戏的目标是找到所有地雷在M x N场中的位置.游戏在一个正方形中显示一个数字,它告诉你在这个正方形附近有 多少个地雷.每个方块最多有八 ...
- mybatis 的sql语句及使用mybatis的动态sql mybatis防注入
由于看到写的比较详细的文档这里将之前的删掉了,只留下一些我认为能帮助理解的和关于动态sql及防注入的一些理解.文档链接 :mybatis官方文档介绍 <!-- 根据条件查询用户 --> ...
- Linux—CentOS7下python开发环境配置
CentOS7下python开发环境配置 上一篇博客讲了如何在Centos7下安装python3(https://www.cnblogs.com/zivli/p/9937608.html),这一次配置 ...
- Git Gerrit Code Review
Gerrit Code Review | Gerrit Code Reviewhttps://www.gerritcodereview.com/
- Docker Compose vs. Dockerfile
Docker Compose vs. Dockerfile - which is better? - Stack Overflowhttps://stackoverflow.com/questions ...
- JDBC+Servlet+JSP的学生案例增删改查
数据库信息传输到页面实现. 先进行学生信息页面展示: 接口IStudentDao public interface IStudentDao { /** * 保存操作 * @param stu 学生对象 ...
- C# DataTable详解
添加引用 using System.Data; 创建表 //创建一个空表 DataTable dt = new DataTable(); //创建一个名为"Table_New"的空 ...
- Git发生SSL certificate problem: certificate ha错误的解决方法
这两天,不知道为什么,用Git提交代码到服务器时,总出现SSL certificate problem: unable to get local issuer certificate while ac ...
- 老男孩python学习自修第十九天【异常处理】
1.常见的错误 TypeError 类型错误 NameError 没有该变量 ValueError 不期望的值 AttributeError 没有该属性 UnboundLocalError 没有该局部 ...