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. 10个常用的linux的命令

    以下就是今天我们要介绍的Linux命令:  man  touch, cat and less  sort and grep  cut  sed  tar  find  diff  uniq  chmo ...

  2. Filebeat6.3文档—Log input配置

    Filebeat6.3文档-Log input配置 paths 日志加载的路径.例如加载某一子目录级别下面路径的日志:/var/log/*/*.log.这表示会去加载以.log结尾的/var/log下 ...

  3. ajax具体实现学习记录

    记录自己对ajax\的理解, 首先要明白ajax是为了解决什么问题,简单来讲就是为了局部刷新页面,而不刷新整个界面.就比如现在有一个实时热度的显示,它是不断变化的,所以你肯定要不停的从数据库当中获取热 ...

  4. scrapyd schedule.json setting 传入多个值

    使用案例: import requests adder='http://127.0.0.1:6800' data = { 'project':'v1', 'version':'12379', 'set ...

  5. c#链接数据库,查找数据信息

    using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threa ...

  6. html的一些基本属性介绍

    一.html的属性类型: 1.常见标签属性: a.<h1>:align对其方式      例如:<h1  align="right"> hhhhh</ ...

  7. python基础知识 01

    一.计算机基础知识 计算机有硬件+操作系统+软件应用组成 cpu:人的大脑 内存:人的临时记忆 硬盘:人的永久记忆 操作系统 控制计算机硬件工作的流程 应用程序 安装在操作系统上的软件 二.Pytho ...

  8. windiows下搭建python+selenium+unittest+Chrome的Web自动化环境

    一.selenium.unittest概念 Selenium 是用于测试 Web 应用程序用户界面 (UI) 的常用框架.它是一款用于运行端到端功能测试的超强工具.您可以使用多个编程语言编写测试,并且 ...

  9. 垂直渐变的Button

    public partial class RoundButton : Button { Rectangle r; private Brush _myBrush = null; , , ); , , ) ...

  10. web项目jsp中无法引入js问题

    https://blog.csdn.net/C1042135353/article/details/80274685#commentBox 这篇文章超赞的,几个小时的时间看了这篇文章豁然开朗,瞬间懂了 ...