题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=5273

Wei Qing (died  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:
. 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.
. Emperor Wu wanted Wei’s land to be as large as possible without violating the rule .
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 (, ) 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 ( ≤ K ≤ ) 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) ( ≤ R ≤
, , )
Then a line containing an integer N follows, indicating that there were N ( < N ≤ ) 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.
( ≤ L, T ≤ R, < 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 Sample Output

题意:有一个矩形的地方左下角坐标(0,0),右上角坐标(R,R),里面有N个绿洲,每个绿洲给出左下角坐标(L,T)宽W高H,把这块地以x=n(整数)分成两部分需要满足两个要求

1.左边与右边的绿洲面积差最小。

2.在满足1的条件下,让左边的面积尽量大

输出分割的坐标n

思路:把矩形分成宽为1的单位矩形,算出每个矩形的绿洲面积,从左边找到左边面积大于等于总面积一半的位置    再向后找,如果面积不变化,坐标向后移,直到面积变化停止

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<algorithm>
#include<queue>
#include<math.h>
#include <stack>
using namespace std;
#define ll long long
#define INF 0x3f3f3f3f
#define met(a,b) memset(a,b,sizeof(a))
#define mod 2147493647
#define N 1000010
ll sum[N];
int main()
{
int t,x,y;
ll l,w;
scanf("%d",&t);
int r,n;
while(t--)
{
scanf("%d",&r);
scanf("%d",&n);
ll S=;
met(sum,);
for(int i=; i<n; i++)
{
scanf("%d %d %lld %lld",&x,&y,&w,&l);
S+=w*l;///求总面积
for(int j=x; j<=x+w- && j<=r- ;j++)
{
sum[j]+=l;///记录每个单位的面积变化
}
}
ll ans=;
int i,j;
for(i=; i<r; i++)
{
ans+=sum[i];
if(ans* >= S)///找到一个刚好大于或等于s的地方,如果不能平分,多的一份给左边
break;
}
ll ans1=ans;
for(j=i+;j<r;j++)
{
ans1+=sum[j];
if(ans1!=ans)///如果往后面积绿洲面积没变,西边拥有的面积可以增加
break;
}
printf("%d\n",j);
}
return ;
}

(UVALive 7261)Xiongnu's Land 二分的更多相关文章

  1. UVALive 7261 Xiongnu's Land (扫描线)

    Wei Qing (died 106 BC) was a military general of the Western Han dynasty whose campaigns against the ...

  2. UVALive - 7261 Xiongnu's Land

    思路: 先二分下界,再二分上届. #include <bits/stdc++.h> using namespace std; #define MP make_pair #define PB ...

  3. 二分+贪心 hihocoder 1249 Xiongnu's Land (15北京A)

    题目传送门 题意:有多个矩形分布在[0, 0]到[R, R]的的范围内,画一条竖线分割成两块矩形,使得左边包括矩形的面积大于等于右边的面积,在这个前提下使得画的竖线尽量远 分析:二分答案,当面积相等时 ...

  4. [ An Ac a Day ^_^ ] HihoCoder 1249 Xiongnu's Land 线性扫描

    拿到了icpc北京站的参赛名额 感谢亮哥~ 虽然是地狱之战 但也要全力以赴! 题意: 有一片沙漠 n片绿洲 让你用一条线分成两部分 左≥右 而且分割线要尽量靠右 问线的位置 思路: 网上说可以二分 没 ...

  5. Gym 101194D / UVALive 7900 - Ice Cream Tower - [二分+贪心][2016 EC-Final Problem D]

    题目链接: http://codeforces.com/gym/101194/attachments https://icpcarchive.ecs.baylor.edu/index.php?opti ...

  6. 2015北京区域赛 Xiongnu's Land

    Wei Qing (died 106 BC) was a military general of the Western Han dynasty whose campaigns against the ...

  7. UVALive 6656 Watching the Kangaroo --二分

    题意:给你一些区间,再查询一些点,问这些点与所有区间形成的最小距离的最大值.最小距离定义为:如果点在区间内,那么最小距离为0,否则为min(pos-L[i],R[i]-pos). 解法:当然要排个序, ...

  8. hdu-----(1507)Uncle Tom's Inherited Land*(二分匹配)

    Uncle Tom's Inherited Land* Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (J ...

  9. UVALive 3635 Pie 切糕大师 二分

    题意:为每个小伙伴切糕,要求每个小盆友(包括你自己)分得的pie一样大,但是每个人只能分得一份pie,不能拿两份凑一起的. 做法:二分查找切糕的大小,然后看看分出来的个数有没有大于小盆友们的个数,它又 ...

随机推荐

  1. Codeforces Gym 100513M M. Variable Shadowing 暴力

    M. Variable Shadowing Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100513/ ...

  2. 2013年中国区Skyline软件价格体系

    < 2013年中国区Skyline软件价格体系                         序号 产品名称 描述 市场报价         1 TerraExplorer Pro 5.1 对 ...

  3. 将PHP作为Shell脚本语言使用

    我们都知道.PHP是一种非常好的动态网页开发语言(速度飞快.开发周期短--).可是仅仅有非常少数的人意识到PHP也能够非常好的作为编写Shell脚本的语言,当PHP作为编写Shell脚本的语言时,他并 ...

  4. oracle internal :VIEW: X$KCBLDRHIST - Direct Read HISTory

    WebIV:View NOTE:159900.1     Note (Sure) - Note    Mods - Note Refs Error ORA 600 TAR TAR-Info Bug B ...

  5. Playing with ptrace, Part II

    Playing with ptrace, Part II Issue From Issue # December Dec , By Pradeep Padala inSysAdmin In Part ...

  6. C#_uploadify_mvc_version

    jQuery Uploadify在ASP.NET MVC3中的使用 1.Uploadify简介 Uploadify是基于jQuery的一种上传插件,支持多文件.带进度条显示上传,在项目开发中常被使用. ...

  7. hdu1051 Wooden Sticks

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=1051 大意:求最少升序序列的个数. #include <cstdio> #include &l ...

  8. 20+ Rsync command’s switches and common usages with examples – Unix/Linux--reference

    reference:http://crybit.com/rsync-commands-switches/ The “rsync” is a powerful command under the Lin ...

  9. PHP.6-PHP环境搭建(Windows环境下)-LAMP

    PHP环境搭建(Windows环境下)-LAMP Windows系统上分别独立安装Apache2.PHP5.MySQL5和phpMyAdmin等几个软件.独立安装的好处是可以自由选择这些组件的具体版本 ...

  10. myeclipse2014 安装maven3.3.9和mave配置本地仓库

    昨天晚上发现eclipse下一个aptana JS的编辑插件,就想装到myeclipse下,结果悲剧了,myeclipse每次启动都闪退,虽然最后解决了,但是myeclipse里面的自带插件不知少了好 ...