题目链接

Brownie Points II

Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 207    Accepted Submission(s): 77

Problem Description
Stan 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.

Input
Input 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). 
Output
For 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 Input
11
3 2
3 3
3 4
3 6
2 -2
1 -3
0 0
-3 -3
-3 -2
-3 -4
3 -7
0
Sample Output
Stan: 7; Ollie: 2 3;
Accepted Code:
 /*************************************************************************
> 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的更多相关文章

  1. hdu 1156 && poj 2464 Brownie Points II (BIT)

    2464 -- Brownie Points II Problem - 1156 hdu分类线段树的题.题意是,给出一堆点的位置,stan和ollie玩游戏,stan通过其中一个点画垂线,ollie通 ...

  2. 转载:hdu 题目分类 (侵删)

    转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...

  3. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  4. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  5. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

  6. HDU 4569 Special equations(取模)

    Special equations Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  7. HDU 4006The kth great number(K大数 +小顶堆)

    The kth great number Time Limit:1000MS     Memory Limit:65768KB     64bit IO Format:%I64d & %I64 ...

  8. HDU 1796How many integers can you find(容斥原理)

    How many integers can you find Time Limit:5000MS     Memory Limit:32768KB     64bit IO Format:%I64d ...

  9. hdu 4481 Time travel(高斯求期望)(转)

    (转)http://blog.csdn.net/u013081425/article/details/39240021 http://acm.hdu.edu.cn/showproblem.php?pi ...

随机推荐

  1. php构造方法(函数)基础

    什么是构造函数呢?在回答这个问题之前,我们来看一个需求:我们在创建人类的对象时,是先把一个对象创建好后,再给他的年龄和姓名属性赋值,如果现在我要求,在创建人类的对象时,就指定这个对象的年龄和姓名,该怎 ...

  2. PAT甲级——A1084 Broken Keyboard

    On a broken keyboard, some of the keys are worn out. So when you type some sentences, the characters ...

  3. 05_springmvc参数绑定

    一.参数绑定的过程 从客户端请求key/value数据,经过参数绑定,将key/value数据绑定到controller方法的形参上.springmvc中,接收页面提交的数据是通过方法形参来接收.而不 ...

  4. ES6之主要知识点(九)Set和Map

    1.Set ES6 提供了新的数据结构 Set.它类似于数组,但是成员的值都是唯一的,没有重复的值. Set 本身是一个构造函数,用来生成 Set 数据结构. const s = new Set(); ...

  5. day65作业

    有 红.黄.蓝 三个按钮,以及一个200x200矩形框box,点击不同的按钮,box的颜色会被切换为指定的颜色 <body> <div id="app"> ...

  6. xcode下的DerivedData

    在模拟器运行的情况下经常会出现以下的错误: error: remove /Users/mac/Library/Developer/Xcode/DerivedData/YuQing-amkrrucjrn ...

  7. 深入浅出 Java Concurrency (20): 并发容器 part 5 ConcurrentLinkedQueue[转]

    ConcurrentLinkedQueue是Queue的一个线程安全实现.先来看一段文档说明. 一个基于链接节点的无界线程安全队列.此队列按照 FIFO(先进先出)原则对元素进行排序.队列的头部 是队 ...

  8. 【agc013d】AtCoder Grand Contest 013 D - Piling Up

    题意 盒子里有n块砖,每块的颜色可能为蓝色或红色. 执行m次三步操作: 1.从盒子里随便拿走一块砖 2.放入一块蓝砖和红砖到盒子里 3.从盒子里随便拿走一块砖 给定n,m 问拿出来的砖,可能有多少种不 ...

  9. python intern(字符串驻留机制)

    python 中为了提高字符串的使用用效率和节约内存,对于由 字母.数字.下划线组成的标识符采用了 intern 机制,即对于短字符串,将其赋值给多个对象时,内存中只有一个副本,多个对象共享这个副本. ...

  10. VC++1.5太伟大了

    功能样样俱全,一点不比现在的VS系列差 VC++1.5全貌,虽然很古老,但是已经可以了. 新建的文档试图,多文档工程,很像样 文档试图,单文档工程,已经非常像样了,和记事本差不多了 这是资源编辑器,寒 ...