Hdu 1156
Brownie Points II
Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 207 Accepted Submission(s): 77Problem DescriptionStan and Ollie play the game of Odd Brownie Points. Some brownie points are located in the plane, at integer coordinates. Stan plays first and places a vertical line in the plane. The line must go through a brownie point and may cross many (with the same x-coordinate). Then Ollie places a horizontal line that must cross a brownie point already crossed by the vertical line.
Those lines divide the plane into four quadrants. The quadrant containing points with arbitrarily large positive coordinates is the top-right quadrant.The players score according to the number of brownie points in the quadrants. If a brownie point is crossed by a line, it doesn't count. Stan gets a point for each (uncrossed) brownie point in the top-right and bottom-left quadrants. Ollie gets a point for each (uncrossed) brownie point in the top-left and bottom-right quadrants.
Stan and Ollie each try to maximize his own score. When Stan plays, he considers the responses, and chooses a line which maximizes his smallest-possible score.
InputInput contains a number of test cases. The data of each test case appear on a sequence of input lines. The first line of each test case contains a positive odd integer 1 < n < 200000 which is the number of brownie points. Each of the following n lines contains two integers, the horizontal (x) and vertical (y) coordinates of a brownie point. No two brownie points occupy the same place. The input ends with a line containing 0 (instead of the n of a test).OutputFor each input test, print a line of output in the format shown below. The first number is the largest score which Stan can assure for himself. The remaining numbers are the possible (high) scores of Ollie, in increasing order.Sample Input11
3 2
3 3
3 4
3 6
2 -2
1 -3
0 0
-3 -3
-3 -2
-3 -4
3 -7
0Sample OutputStan: 7; Ollie: 2 3;
/*************************************************************************
> File Name: A.cpp
> Author: Stomach_ache
> Mail: sudaweitong@gmail.com
> Created Time: 2014年07月27日 星期日 14时45分32秒
> Propose:
************************************************************************/ #include <cmath>
#include <string>
#include <vector>
#include <cstdio>
#include <fstream>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std; const int maxn = ;
//l维护垂直线左侧的点,r维护垂直线右侧的点
int l[maxn], r[maxn];
//每一条垂直于x轴的直线信息
struct Line {
int x, y;
friend bool operator < (Line a, Line b) {
return a.x < b.x;
}
}line[maxn];
//保存所有y轴坐标
int y[maxn];
int n, w; //BIT
int lowbit(int x) {
return x & -x;
} void add(int t[], int x, int v) {
while (x <= w) {
t[x] += v;
x += lowbit(x);
}
} int sum(int t[], int x) {
int res = ;
while (x > ) {
res += t[x];
x -= lowbit(x);
}
return res;
} int main(void) {
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
#endif
while (~scanf("%d", &n) && n) {
for (int i = ; i < n; i++) {
scanf("%d %d", &line[i].x, &line[i].y);
y[i] = line[i].y;
}
//y轴坐标离散化
sort(y, y + n);
w = unique(y, y + n) - y;
//按x轴坐标从小到大排序
sort(line, line + n);
//初始化BIT数组
memset(l, , sizeof(l));
memset(r, , sizeof(r));
//把所有点加入右侧的BIT
for (int i = ; i < n; i++) add(r, lower_bound(y, y + w, line[i].y)+-y, );
//Stan是其可以获得的最大的最小值
//st保存重复x坐标出现的起点
int Stan = -, st = ;
//保存Ollie可能的结果
vector<int> Ollie;
for (int i = ; i <= n; i++) {
if (i == n || line[i].x != line[i-].x) {
//把重复的点从右侧BIT中删除
for (int j = st; j < i; j++) add(r, lower_bound(y, y + w, line[j].y)+-y, -);
int stan = -, ollie = -;
//扫描x坐标重复的点,枚举平行于x轴的直线
for (int j = st; j < i; j++) {
int f = lower_bound(y, y + w, line[j].y) + - y;
int s = sum(l, f-) + sum(r, w) - sum(r, f);
int o = sum(l, w) - sum(l, f) + sum(r, f-);
//为了使ollie最大
if (o > ollie) {
ollie = o;
stan = s;
} else if (o == ollie) {
stan = min(stan, s);
}
}
//更新最大的最小值
if (stan > Stan) {
Stan = stan;
Ollie.clear();
Ollie.push_back(ollie);
} else if (stan == Stan) {
Ollie.push_back(ollie);
}
//把重复的点加入左侧的BIT
for (int j = st; j < i; j++) add(l, lower_bound(y, y + w, line[j].y)+-y, );
st = i;
}
}
//注意要将Ollie的结果去重
sort(Ollie.begin(), Ollie.end());
int len = unique(Ollie.begin(), Ollie.end()) - Ollie.begin();
printf("Stan: %d; Ollie:", Stan);
for (int i = ; i < len; i++) printf(" %d", Ollie[i]);
puts(";");
} return ;
}
Hdu 1156的更多相关文章
- hdu 1156 && poj 2464 Brownie Points II (BIT)
2464 -- Brownie Points II Problem - 1156 hdu分类线段树的题.题意是,给出一堆点的位置,stan和ollie玩游戏,stan通过其中一个点画垂线,ollie通 ...
- 转载:hdu 题目分类 (侵删)
转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 【HDU 3037】Saving Beans Lucas定理模板
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...
- hdu 4859 海岸线 Bestcoder Round 1
http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...
- HDU 4569 Special equations(取模)
Special equations Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- HDU 4006The kth great number(K大数 +小顶堆)
The kth great number Time Limit:1000MS Memory Limit:65768KB 64bit IO Format:%I64d & %I64 ...
- HDU 1796How many integers can you find(容斥原理)
How many integers can you find Time Limit:5000MS Memory Limit:32768KB 64bit IO Format:%I64d ...
- hdu 4481 Time travel(高斯求期望)(转)
(转)http://blog.csdn.net/u013081425/article/details/39240021 http://acm.hdu.edu.cn/showproblem.php?pi ...
随机推荐
- 03_Spring Bean的装配模式_基于Annotation配置方式
前言 在Spring中尽管使用XML配置文件可以实现Bean的装配工作,但如果应用中Bean的数量较多,会导致XML配置文件过于臃肿,从而给维护和升级带来一定的困难.从JDK 5开始提供了名为Anno ...
- Vuejs之Component slot 插槽详解
Vuejs的component的数据进行了沙箱隔离,除js全局变量如Math, Date之类外无法访问用户自定义的变量,所以使用component写组件或嵌套组件时明白变量的访问非常重要 编译作用域 ...
- Linux 启动dubbo管控台:
- vue:element-ui输入框绑定回车事件
参考: https://segmentfault.com/q/1010000011347642 https://weiku.co/article/297/ vue监听input输入框的回车事件:key ...
- linux crontab定时任务运行shell脚本(shell执行sql文件)
https://www.cnblogs.com/tiankongjava/p/6106743.html 今天做个linux定时任务(每晚12点把表汇总). 顺便写个博客记录一下~~ 为什么用linux ...
- Selenium浏览器自动化测试使用(1)
Selenium - 介绍 Selenium是一个开源的和便携式的自动化软件测试工具,用于测试Web应用程序有能力在不同的浏览器和操作系统运行.Selenium真的不是一个单一的工具,而是一套工具,帮 ...
- windows 遍历目录下的所有文件 FindFirstFile FindNextFile
Windows下遍历文件时用到的就是FindFirstFile 和FindNextFile 首先看一下定义: HANDLE FindFirstFile( LPCTSTR lpFileName, // ...
- PHP 类与对象 全解析方法
1.类与对象 对象:实际存在该类事物中每个实物的个体.$a =new User(); 实例化后的$a 引用�php的别名,两个不同的变量名字指向相同的内容 封装: 把对象的属性和方法组织在一个类(逻辑 ...
- [Swoole系列入门教程 5] UDP协议和demo
• 客户端服务端没有任何联系 • 指定地址跟端口,不关心消息是否发送成功 • 心跳检测不能影响到客户端• udp建立长连接
- day20 作业
目录 今日作业 1.下面这段代码的输出结果将是什么?请解释. 2.多重继承的执行顺序,请解答以下输出结果是什么?并解释. 3.什么是新式类,什么是经典类,二者有什么区别?什么是深度优先,什么是广度优先 ...