Wei Qing (died 106 BC) was a military general of the Western Han dynasty whose campaigns against 
the Xiongnu earned him great acclaim. He was a relative of Emperor Wu because he was the younger 
half-brother of Empress Wei Zifu (Emperor Wu’s wife) and the husband of Princess Pingyang. He was 
also the uncle of Huo Qubing, another notable Han general who participated in the campaigns against 
the Xiongnu and exhibited outstanding military talent even as a teenager. 
Defeated by Wei Qing and Huo Qubing, the Xiongnu sang: “Losing my Qilian Mountains, made 
my cattle unthriving; Losing my Yanzhi Mountains, made my women lacking rouge.” 
The text above is digested from Wikipedia. Since Wei and Huo’s distinguished achievements, 
Emperor Wu decided to give them some awards — a piece of land taken by them from Xiongnu. This 
piece of land was located in a desert, and there were many oases in it. Emperor Wu wanted to draw 
a straight south-to-north dividing line to divide the land into two parts, and gave the western part to 
Wei Qing while gave the eastern part to Huo Qubing. There are two rules about the land dividing: 
1. The total area of the oases lay in Wei’s land must be larger or equal to the total area of the oases 
lay in Huo’s land, and the difference must be as small as possible. 
2. Emperor Wu wanted Wei’s land to be as large as possible without violating the rule 1. 
To simplify the problem, please consider the piece of land given to Wei and Huo as a square on a 
plane. The coordinate of its left bottom corner was (0,0) and the coordinate of its right top corner 
was (R, R). Each oasis in this land could also be considered as a rectangle which was parallel to the 
coordinate axes. The equation of the dividing line was like x = n, and n must be an integer. If the 
dividing line split an oasis, then Wei owned the western part and Huo owned the eastern part. Please 
help Emperor Wu to find out how to draw the dividing line. 
Input 
The first line of the input is an integer K meaning that there are K (1 ≤ K ≤ 15) test cases. 
For each test case: 
The first line is an integer R, indicating that the land’s right top corner was at (R, R) (1 ≤ R ≤ 
1,000,000) 
Then a line containing an integer N follows, indicating that there were N (0 < N ≤ 10000) oases. 
Then N lines follow, each contains four integers L, T, W and H, meaning that there was an 
oasis whose coordinate of the left top corner was (L, T), and its width was W and height was H. 
(0 ≤ L, T ≤ R, 0 < W, H ≤ R). No oasis overlaps. 
Output 
For each test case, print an integer n, meaning that Emperor Wu should draw a dividing line whose 
equation is x = n. Please note that, in order to satisfy the rules, Emperor might let Wei get the whole 
land by drawing a line of x = R if he had to. 
Sample Input 

1000 

1 1 2 1 
5 1 2 1 
1000 

1 1 2 1 
Sample Output 

2

题意:沙漠中有许多块矩形水源,水源不相交,问能否找到一根中轴线,使得轴线左边的水源面积大于等于右边的水源面积。在满足两个面积之差最小的情况下,使得轴线靠近右端点

用二分法求,否则时间超限

#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
int n;
struct point{
int x,y,w,h;
};
point a[];
/*bool cmp(point p,point q){
return p.x<q.x;
}*/
ll cal(int x){
ll sum = ;
for(int i=;i<n;i++){
if(a[i].x < x){
sum += (ll)( min( (a[i].w+a[i].x),x) - a[i].x) * a[i].h;
}
}
return sum;
}
int main(){
int T,R,w,h;
ll total;
while(cin >> T){
while(T--){
total = ;
cin >> R;
cin >> n;
for(int i=;i<n;i++){
cin >> a[i].x >> a[i].y >> a[i].w >> a[i].h;
total += (ll)a[i].h*a[i].w;//注意每次都要取long long 否则答案错误 }
// sort(a,a+n,cmp);
int l,r,mid;
ll tmp;
l = ,r = R;
while(l<r){
mid = (r+l)/;
tmp = cal(mid);
if(*tmp<total){
l = mid + ;
}else r = mid;
}
tmp = cal(r);
while(cal(r) == tmp && r<=R){
r ++;
}
cout << r- << endl;
}
}
return ;
}

2015北京区域赛 Xiongnu's Land的更多相关文章

  1. 2015北京区域赛 Mysterious Antiques in Sackler Museum 几何基础+思维

    题意是,选出三个,看看是否可以凑成一个新的矩形. #include<bits/stdc++.h> using namespace std; struct node { ]; }a[]; b ...

  2. 2015北京网络赛 D-The Celebration of Rabbits 动归+FWT

    2015北京网络赛 D-The Celebration of Rabbits 题意: 给定四个正整数n, m, L, R (1≤n,m,L,R≤1000). 设a为一个长度为2n+1的序列. 设f(x ...

  3. 2015北京网络赛 J Scores bitset+分块

    2015北京网络赛 J Scores 题意:50000组5维数据,50000个询问,问有多少组每一维都不大于询问的数据 思路:赛时没有思路,后来看解题报告也因为智商太低看了半天看不懂.bitset之前 ...

  4. 2015北京网络赛 Couple Trees 倍增算法

    2015北京网络赛 Couple Trees 题意:两棵树,求不同树上两个节点的最近公共祖先 思路:比赛时看过的队伍不是很多,没有仔细想.今天补题才发现有个 倍增算法,自己竟然不知道.  解法来自 q ...

  5. HDU5556 Land of Farms(二分图 2015 合肥区域赛)

    容易想到将问题转化为求图的独立数问题 ,但求一般图的独立集是一个NPC问题,需要一些转化. 状态压缩,枚举每个上古农场是否选择,然后将剩下的新农场根据i + j奇偶性分为x , y集. 结果为 max ...

  6. 2017 ACM-ICPC 北京区域赛记录

    ------------------------------------------------------------------------------ 出发日 拖着一个大箱子走是真的累. 下午三 ...

  7. 2015 北京网络赛 C Protecting Homeless Cats hihoCoder 1229 树状数组

    题意:求在平面上 任意两点连线,原点到这个点的距离小于d的点对有多少个,n=200000; 解: 以原点为圆心做一个半径为d的圆,我们知道圆内的点和园内以外的点的连线都是小于d的还有,圆内和园内的点联 ...

  8. 2015沈阳区域赛Meeting(最短路 + 建图)

    Meeting Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total ...

  9. Hiho coder 1236 2015 北京网络赛 Score

    五维偏序..一开始被吓到了,后来知道了一种BITSET分块的方法,感觉非常不错. 呆马: #include <iostream> #include <cstdio> #incl ...

随机推荐

  1. DesignPattern系列__03依赖倒置原则

    依赖倒置原则(Dependence Inversion Priiciple,DIP) 介绍 High level modules should not depend upon low level mo ...

  2. Unity经典游戏教程之:冒险岛

    版权声明: 本文原创发布于博客园"优梦创客"的博客空间(网址:http://www.cnblogs.com/raymondking123/)以及微信公众号"优梦创客&qu ...

  3. 个人使用的lilypond第一个模板

    手残非要用lilypond打谱真是…… 可是lilypond又能满足各种细节标记和谱文混排,这是musescore达不到的 所以还是开这个坑,希望能逐渐自己有能力编写自己的音乐教材 个人用Fresco ...

  4. 完全零基础在Linux中安装 JDK

    完全零基础在Linux中安装 JDK 总体思路:先确定没有Java程序了 — 然后创建相应路径文件夹 — 下载JDK — 解压到当前路径 — 自定义文件名称 — 配置环境变量 — 检查是否安装成功 第 ...

  5. java 各基本类型转 bytes 数组

    java 将 基本类型转byte[] 数组时,需考虑大端小端问题 1. 大端格式下,基本类型与byte[]互转 BigByteUtil.java package com.ysq.util; impor ...

  6. java-极光推送教程

    一.准备工作: 1.访问极光推送官网:https://www.jiguang.cn/accounts/login/form 2.注册登陆,拿到appKey和masterSecret 3.创建一个应用, ...

  7. HTML/CSS:display:flex 布局教程

    网页布局(layout)是 CSS 的一个重点应用. 布局的传统解决方案,基于盒状模型,依赖 display 属性 + position属性 + float属性.它对于那些特殊布局非常不方便,比如,垂 ...

  8. 带图标和多行显示的ListBox

    源码https://www.codeproject.com/Articles/15464/Extending-the-ListBox-to-show-more-complex-items 定义控件 u ...

  9. JS如何重写一个函数

    分享一些自己在开发上遇到的问题,比如我们页面上用了大量的打印语句,但是在某些时候,我们不想要了. 解决方案1 : 我们删除这里的代码,如果太多了,那工作量太大好累,想想都不想干 解决方案2 :我们将c ...

  10. Nginx总结(二)基于ip的虚拟主机配置

    前面讲了如何安装配置Nginx,大家可以去这里看看nginx系列文章:https://www.cnblogs.com/zhangweizhong/category/1529997.html 今天要说的 ...