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

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

思路:做两次二分就好了

 1 #include <stdio.h>
 2 #include <iostream>
 3 #include <algorithm>
 4 using namespace std;
 5 #define xx first
 6 #define yy second
 7 struct node{
 8     int len,wid;
 9     long long sum;
10     pair<int,int> p1;
11     pair<int,int> p2;
12     void cal(){
13         p2.xx=p1.xx+len;
14         p2.yy=p1.yy-wid;
15         sum=(long long)len*wid;
16     }
17 };
18 bool cmp(const node&a,const node&b){
19     return a.p1.xx<b.p1.xx;
20 }
21 const int maxn=1e4+10;
22 node a[maxn];
23 int n,r;
24 long long check(int x){
25     long long tmp=0;
26     for(int i=1;i<=n;i++){
27         tmp+=((long long )a[i].wid*max(min(a[i].len,x-a[i].p1.xx),0));
28     }
29     return tmp;
30 }
31 int binary_search(int R,long long sum){
32     int l=-1,r=R+1;
33     int mid;
34     while(r-l>1){
35         mid=(l+r)>>1;
36         long long tmp=check(mid);
37         if(tmp>=sum-tmp){
38             r=mid;
39         }
40         else l=mid;
41     }
42     long long ans=check(r);
43     l=-1,r=R+1;
44     while(r-l>1){
45          mid=(l+r)>>1;
46         long long tmp=check(mid);
47         if(tmp>ans) r=mid;
48         else l=mid;
49     }
50     return l;
51 }
52 int main(){
53     int T;
54     //freopen("C:\\Users\\acm\\Desktop\\2015Beijing\\in.txt","r",stdin);
55     scanf("%d",&T);
56     while(T--){
57         scanf("%d",&r);
58         scanf("%d",&n);
59         long long sum=0;
60         for(int i=1;i<=n;i++){
61             int x,y,len,wid;
62             scanf("%d %d %d %d",&x,&y,&len,&wid);
63             sum+=((long long)len*wid);
64             a[i].len=len,a[i].wid=wid,a[i].p1=make_pair(x,y),a[i].cal();
65         }
66         sort(a+1,a+1+n,cmp);
67         printf("%d\n",binary_search(r,sum));
68     }
69     return 0;
70 }

转载于:https://www.cnblogs.com/as3asddd/p/6041066.html

hiho1249 Xiongnu's Land相关推荐

  1. 2015acm区域赛北京

    A.Xiongnu's Land 二分答案 题意: R*R的平面上给你n个矩形,你要找到一条竖直的直线x=k,使得直线左边的矩形面积和大于等于右边的矩形面积和,而且它们的差值要尽量小,并且k要尽量大 ...

  2. [ARC072C]Alice in linear land(dp,贪心)

    [ARC072C]Alice in linear land Description 给定a1...ana_1...a_na1​...an​和DDD,mmm轮询问,每轮询问给你一个qqq,可以让你任意修 ...

  3. 【HDU - 5050 】Divided Land (Java大数,大数进制转换,大数gcd)

    题干: It's time to fight the local despots and redistribute the land. There is a rectangular piece of ...

  4. How Many Pieces of Land ? (UVA-10213)

    Problem Description You are given an elliptical shaped land and you are asked to choose n arbitrary ...

  5. 吴恩达深度学习5.1练习_Sequence Models_Character level language model - Dinosaurus land

    转载自吴恩达老师深度学习课程作业notebook Character level language model - Dinosaurus land Welcome to Dinosaurus Isla ...

  6. UVA10213 How Many Pieces of Land【数学+大数】

    You are given an elliptical shaped land and you are asked to choose n arbitrary points on its bounda ...

  7. UVA516 POJ1365 LA5533 ZOJ1261 Prime Land【欧拉筛法】

    Everybody in the Prime Land is using a prime base number system. In this system, each positive integ ...

  8. UVA10074 Take the Land【最大子段和+DP】

    The poor man went to the King and said, "Lord, I cannot maintain my family. Please give me some ...

  9. Lucky Kat LAND — NFT 系列发售

    Lucky Kat Studios 在北京时间 5 月 11 日晚上 11 点发布 NFT 系列,包括 Lucky Kat Land 中的人物.设备和建筑! Lucky Kat Land 是元宇宙中一 ...

最新文章

  1. .net项目文档生成工具使用
  2. react页面数据过多怎么办_性能!!让你的 React 组件跑得再快一点,收藏
  3. [知识图谱]利用py2neo从Neo4j数据库获取数据
  4. C# 网络编程之webBrowser获取网页url和下载网页中图片
  5. 怎样用Jquery实现拖拽层,并实现网站自定义化模块功能?
  6. 电脑内部录音教程Virtual Audio Cable使用教程
  7. linux系统多网口聚合配置,Linux网卡聚合linux多网卡绑定聚合之bond模式的原理是什么...
  8. 在android中ScrollView嵌套ScrollView解决方案
  9. Java高并发编程详解系列-线程池原理自定义线程池
  10. 一台linux服务器配置多个tomcat应用
  11. m1芯片 服务器,今天来说说苹果M1 和华为ARM PC芯片
  12. PMP第六版十五至尊图记忆方法
  13. dcp-9020cdn复印位置有_兄弟DCP-9020CDN打印机驱动下载
  14. 成功解决3dmax中,旋转时透视图可以看穿物体
  15. 【报表福利大放送】100余套报表模板免费下
  16. 一米村长讲故事机器人_村长讲故事
  17. IT行业就业前景如何
  18. 『矩阵论笔记』详解最小二乘法(矩阵形式求导)+Python实战
  19. idea在线激活 16
  20. 银行付款出现java,SSH框架网上商城项目第22战之银行图标以及支付页面显示

热门文章

  1. STC12C5A60S2笔记8(串口)
  2. 要活多久才能赚回你交的养老金
  3. UImageview加边框 加阴影
  4. founder of girton college
  5. python for in list
  6. graduation wishes from professor Youmin Xi
  7. LUA ipairs遍历的问题
  8. Bfs++ open the lock
  9. 计算机架构及开机过程
  10. Android RecyclerView设计通用Adapter