2015北京区域赛 Xiongnu's Land
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
2
1000
2
1 1 2 1
5 1 2 1
1000
1
1 1 2 1
Sample Output
5
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的更多相关文章
- 2015北京区域赛 Mysterious Antiques in Sackler Museum 几何基础+思维
题意是,选出三个,看看是否可以凑成一个新的矩形. #include<bits/stdc++.h> using namespace std; struct node { ]; }a[]; b ...
- 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 ...
- 2015北京网络赛 J Scores bitset+分块
2015北京网络赛 J Scores 题意:50000组5维数据,50000个询问,问有多少组每一维都不大于询问的数据 思路:赛时没有思路,后来看解题报告也因为智商太低看了半天看不懂.bitset之前 ...
- 2015北京网络赛 Couple Trees 倍增算法
2015北京网络赛 Couple Trees 题意:两棵树,求不同树上两个节点的最近公共祖先 思路:比赛时看过的队伍不是很多,没有仔细想.今天补题才发现有个 倍增算法,自己竟然不知道. 解法来自 q ...
- HDU5556 Land of Farms(二分图 2015 合肥区域赛)
容易想到将问题转化为求图的独立数问题 ,但求一般图的独立集是一个NPC问题,需要一些转化. 状态压缩,枚举每个上古农场是否选择,然后将剩下的新农场根据i + j奇偶性分为x , y集. 结果为 max ...
- 2017 ACM-ICPC 北京区域赛记录
------------------------------------------------------------------------------ 出发日 拖着一个大箱子走是真的累. 下午三 ...
- 2015 北京网络赛 C Protecting Homeless Cats hihoCoder 1229 树状数组
题意:求在平面上 任意两点连线,原点到这个点的距离小于d的点对有多少个,n=200000; 解: 以原点为圆心做一个半径为d的圆,我们知道圆内的点和园内以外的点的连线都是小于d的还有,圆内和园内的点联 ...
- 2015沈阳区域赛Meeting(最短路 + 建图)
Meeting Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total ...
- Hiho coder 1236 2015 北京网络赛 Score
五维偏序..一开始被吓到了,后来知道了一种BITSET分块的方法,感觉非常不错. 呆马: #include <iostream> #include <cstdio> #incl ...
随机推荐
- Eclipse中代码自动添加注释及代码注释模板
介绍 为了提高代码的可读性以及为了有些代码有洁癖的人的需求,我们要从学生到职业进行迈进的过程中,必须把以前的那种代码可读性不高的习惯改掉,因为我们必须要与企业接轨.. 好了,废话不多说,反正就是提升自 ...
- 佳木斯集训Day2
D2好点了,最起码不像之前那么水 T1按照常规操作是个找规律,类似于括号匹配的题,但是又不是,推进栈里,然后看最长的左括号有多少个,然后直接cout就可以了 #include <bits/std ...
- javaweb基础整理随笔------jstl与el表达式
虽然jsp中可以写java代码,但是现在不推荐这么做. jsp虽然本质是servlet,但是主要作用只是视图,视图的任务就是显示响应,而不是在JSP中做任何关于程序控制和业务逻辑的事情.所以在JSP页 ...
- Xamarin Android 监听音量键(下)
上篇在 MainActivity 中重写了按键事件(OnKeyDown),获取了音量键键值并打印了出来,当然,手机物理按键和虚拟按键(音量键.返回键.菜单键等)均可通过该按键事件被捕获. 但是,按键重 ...
- Linux curl 表单登录或提交与cookie使用
本文主要讲解通过curl 实现表单提交登录.单独的表单提交与表单登录都差不多,因此就不单独说了. 说明:针对curl表单提交实现登录,不是所有网站都适用,原因是有些网站后台做了限制或有其他校验.我们不 ...
- 在Vue 中使用Typescript
Vue 中使用 typescript 什么是typescript typescript 为 javaScript的超集,这意味着它支持所有都JavaScript都语法.它很像JavaScript都强类 ...
- golang常用的http请求操作
之前用python写各种网络请求的时候写的非常顺手,但是当打算用golang写的时候才发现相对来说还是python的那种方式用的更加顺手,习惯golang的用法之后也就差别不大了,下面主要整理了常用的 ...
- 如何删除GIT仓库中的敏感信息
如何删除GIT仓库中的敏感信息 正常Git仓库中应该尽量不包含数据库连接/AWS帐号/巨大二进制文件,否则一旦泄漏到Github,这些非常敏感信息会影响客户的信息安全已经公司的信誉.公司可能其它还有相 ...
- 前端面试题集锦(二)之CSS部分
1.CSS中的选择器都有哪些?权限情况如何? 解答: (1)类选择器 .className (2) ID选择器 #id (3) 元素选择器 div 可以多个,以逗号隔开 (4)父子选择器 以空格隔 ...
- java-初读 HashTable
有用的标识符 transiant 有用的属性 初始容量11 加载因子0.75 这里理解如果要经常插入大量数据可以增大加载因子 有用的方法 @Test public void testNan() { l ...