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 ...
随机推荐
- PHP面向对象魔术方法基本了解
简单介绍 (1) 魔术方法都是系统提供,程序员使用即可. (2) 所有的魔术方法,前面都是以 __ 开头的 _是两个下划线. (3) 我们在自定义函数时,就不要使用 __开头了. (4) 魔术方法是 ...
- python面向对象应用-1
#猫 定义类 class Cat: type = '猫' #通过__init__初始化的特征 def __init__(self,nickname,age,color): self.nickname ...
- day71test
目录 练习: settings.py views.py: exception.py urls.py 练习: 视图类渲染,解析, 异常配置: 作业: 1..简单过过请求模块的源码流程,建立一个视图类,完 ...
- mybatis第二篇—参数绑定
不管我们在做数据库作业或者任务还是当时的仅靠jdbc来写一个管理系统的时候,sql语句需要一些参数,从而来实现模糊查询,精确查询,插入数据,更新数据和删除数据.这些参数,在mybatis里面,又该如何 ...
- 系统负载load
一.查看系统负荷 如果你的电脑很慢,你或许想查看一下,它的工作量是否太大了. 在Linux系统中,我们一般使用uptime命令查看(w命令和top命令也行).(另外,它们在苹果公司的Mac电脑上也适用 ...
- php 支付宝新版本app支付以及回调
;支付宝快速接入; 支付宝2017年新版本支付基本业务逻辑 服务端生成字符串 交给客户端, 客户端调用接口,将这段字符串str传过去 调用起支付界面. 其中字符串str包含了所有请求参数,以及请求参数 ...
- 数据库顶会VLDB论文解读:阿里数据库智能参数优化的创新与实践
前言 一年一度的数据库领域顶级会议VLDB 2019于美国当地时间8月26日-8月30日在洛杉矶召开.在本届大会上,阿里云数据库产品团队多篇论文入选Research Track和Industrial ...
- [转]iMPACT Spartan-6 FPGA - "WARNING:iMPACT:2217-Error shows in the status register, CRC Error bit is Not 0"
AR# 45304 iMPACT Spartan-6 FPGA - "WARNING:iMPACT:2217-Error shows in the status register, CRC ...
- Java SE、Java EE、Java ME三者的区别
1. Java SE(Java Platform,Standard Edition).Java SE 以前称为 J2SE.它允许开发和部署在桌面.服务器.嵌入式环境和实时环境中使用的 Java 应用程 ...
- R语言画图教程之盒形图
R语言画图教程之盒形图 我们之前有分享过一系列的R语言画图代码(PCA图.Pathway图.火山图.RDA图.热图),今天再来补充一个盒形图(箱形图)的代码. 以下代码只是示例,不能直接搬来用哦,注意 ...