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 ...
随机推荐
- PAT甲级——A1105 Spiral Matrix【25】
This time your job is to fill a sequence of N positive integers into a spiral matrix in non-increasi ...
- 用python打造简单的cms识别
代码 #!/usr/bin/env python3 # coding:utf-8 #lanxing #判断代码,判断是否安装requests库 try: import requests except: ...
- Django之模板语言(三)------>自定义filter
1.自定义filter: 1.在app01下面新建一个templatetags的python package包. 如果没有app01的话,可以通过命令行在manage中进行创建:python mana ...
- 编写函数处理user_list,新方法
写函数,完成以下功能: # 例如有: user_list=[ {"name": "alex","hobby":"抽烟"} ...
- Maven编译资源文件拷贝
<build> <finalName>op-balance-job-service</finalName> <plugins> <plugin&g ...
- Activiti工作流 安装myeclipse activiti设计插件并生成数据库表
从零开始学习Activiti工作流,记录下学习过程. 关于工作流的简介没什么好介绍了,只能说是个很有用的东西,数据库中23张表分别有什么用网上也有很详细的介绍,这里也不多加说明.activiti开发中 ...
- GitHub的使用问题记录
1. github如何收藏和关注? github 中的star作用:star 的作用是收藏,目的是方便以后查找. watch 的作用是关注,目的是等作者更新的时候,你可以收到通知.fork 的作用是参 ...
- Android开发 Camera2开发_2_预览分辨率或拍照分辨率的计算
前言 不管在Camera1或者Camera2在适配不同手机/不同使用场景的情况下都需要计算摄像头里提供的分辨率列表中最合适的那一个分辨率.所以在需要大量机型适配的app,是不建议不经过计算直接自定义分 ...
- 关于set的unordered特性
关于set排序无序的问题,原因是set使用哈希表做内存索引. 详细介绍可见: https://stackoverflow.com/questions/12165200/order-of-unorder ...
- 阿里云HBase Ganos全新升级,推空间、时空、遥感一体化基础云服务
1.HBase Ganos是什么 Ganos是阿里云时空PaaS服务的自研核心引擎.Ganos已作为云数据库时空引擎与数据库平台融合,建立了以自研云原生数据库POALRDB为基础,联合NoSQL大数据 ...