题目链接

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:
  1. /*************************************************************************
  2. > File Name: A.cpp
  3. > Author: Stomach_ache
  4. > Mail: sudaweitong@gmail.com
  5. > Created Time: 2014年07月27日 星期日 14时45分32秒
  6. > Propose:
  7. ************************************************************************/
  8.  
  9. #include <cmath>
  10. #include <string>
  11. #include <vector>
  12. #include <cstdio>
  13. #include <fstream>
  14. #include <cstring>
  15. #include <iostream>
  16. #include <algorithm>
  17. using namespace std;
  18.  
  19. const int maxn = ;
  20. //l维护垂直线左侧的点,r维护垂直线右侧的点
  21. int l[maxn], r[maxn];
  22. //每一条垂直于x轴的直线信息
  23. struct Line {
  24. int x, y;
  25. friend bool operator < (Line a, Line b) {
  26. return a.x < b.x;
  27. }
  28. }line[maxn];
  29. //保存所有y轴坐标
  30. int y[maxn];
  31. int n, w;
  32.  
  33. //BIT
  34. int lowbit(int x) {
  35. return x & -x;
  36. }
  37.  
  38. void add(int t[], int x, int v) {
  39. while (x <= w) {
  40. t[x] += v;
  41. x += lowbit(x);
  42. }
  43. }
  44.  
  45. int sum(int t[], int x) {
  46. int res = ;
  47. while (x > ) {
  48. res += t[x];
  49. x -= lowbit(x);
  50. }
  51. return res;
  52. }
  53.  
  54. int main(void) {
  55. #ifndef ONLINE_JUDGE
  56. freopen("in.txt", "r", stdin);
  57. #endif
  58. while (~scanf("%d", &n) && n) {
  59. for (int i = ; i < n; i++) {
  60. scanf("%d %d", &line[i].x, &line[i].y);
  61. y[i] = line[i].y;
  62. }
  63. //y轴坐标离散化
  64. sort(y, y + n);
  65. w = unique(y, y + n) - y;
  66. //按x轴坐标从小到大排序
  67. sort(line, line + n);
  68. //初始化BIT数组
  69. memset(l, , sizeof(l));
  70. memset(r, , sizeof(r));
  71. //把所有点加入右侧的BIT
  72. for (int i = ; i < n; i++) add(r, lower_bound(y, y + w, line[i].y)+-y, );
  73. //Stan是其可以获得的最大的最小值
  74. //st保存重复x坐标出现的起点
  75. int Stan = -, st = ;
  76. //保存Ollie可能的结果
  77. vector<int> Ollie;
  78. for (int i = ; i <= n; i++) {
  79. if (i == n || line[i].x != line[i-].x) {
  80. //把重复的点从右侧BIT中删除
  81. for (int j = st; j < i; j++) add(r, lower_bound(y, y + w, line[j].y)+-y, -);
  82. int stan = -, ollie = -;
  83. //扫描x坐标重复的点,枚举平行于x轴的直线
  84. for (int j = st; j < i; j++) {
  85. int f = lower_bound(y, y + w, line[j].y) + - y;
  86. int s = sum(l, f-) + sum(r, w) - sum(r, f);
  87. int o = sum(l, w) - sum(l, f) + sum(r, f-);
  88. //为了使ollie最大
  89. if (o > ollie) {
  90. ollie = o;
  91. stan = s;
  92. } else if (o == ollie) {
  93. stan = min(stan, s);
  94. }
  95. }
  96. //更新最大的最小值
  97. if (stan > Stan) {
  98. Stan = stan;
  99. Ollie.clear();
  100. Ollie.push_back(ollie);
  101. } else if (stan == Stan) {
  102. Ollie.push_back(ollie);
  103. }
  104. //把重复的点加入左侧的BIT
  105. for (int j = st; j < i; j++) add(l, lower_bound(y, y + w, line[j].y)+-y, );
  106. st = i;
  107. }
  108. }
  109. //注意要将Ollie的结果去重
  110. sort(Ollie.begin(), Ollie.end());
  111. int len = unique(Ollie.begin(), Ollie.end()) - Ollie.begin();
  112. printf("Stan: %d; Ollie:", Stan);
  113. for (int i = ; i < len; i++) printf(" %d", Ollie[i]);
  114. puts(";");
  115. }
  116.  
  117. return ;
  118. }

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. hibernate使用truncate清空表 截断表

    public void truncateTable(Session session, String tableNameInDb) { String sql = " truncate tabl ...

  2. Mybatis-构建 SqlSessionFactory

    从 XML 中构建 SqlSessionFactory 每 一 个 MyBatis 的 应 用 程 序 都 以 一 个 SqlSessionFactory 对 象 的 实 例 为 核 心 . SqlS ...

  3. java基础之DateFormat类

    DateFormat DateFormat类概述 DateFormat 是日期/时间格式化子类的抽象类,它以与语言无关的方式格式化并解析日期或时间. 是抽象类,所以使用其子类SimpleDateFor ...

  4. Python学习day02 - 编程分类和Pycharm和Jupyter的安装

    编程语言分类 编程语言是用来和计算机交互的,计算机只认识0和1 机器语言(低级语言) 直接和硬件交互 用0和1和计算机沟通 优点:执行效率最高 缺点:开发效率低 汇编语言直接和硬件交互 优点(相较于机 ...

  5. 08_jQuery对象初识(四)each循环、data(非常重要)

    each: 不使用for循环答应jQuery对象,使用each: 退出整个each循环: 退出一次each循环: data:

  6. <每日一题>题目6:二分查找

    #二分查找 ''' 1.end问题 2.44对应的end<start 找不到情况 3.返回值递归的情况 4,611,aim太大的情况 ''' l = [2,3,5,10,15,16,18,22, ...

  7. 记录:vue结合springboot进行分页查询和按条件进行查询

    界面: 主要代码: 搜索框: <el-form ref="searchForm" :inline="true" :model="searchMa ...

  8. [Swoole系列入门教程 1] CentOs 上的Swoole安装

    如果已经用宝塔安装好了PHP, 开启相应的扩展 一.编译安装git clone https://github.com/swoole/swoole-src.git cd swoole-src/ phpi ...

  9. php连接数据库插入数据

    <form action="updata.php" method="post"> 姓名:<input type="text" ...

  10. Docker镜像之commit

    利用 commit 理解镜像构成 基础知识 镜像是容器的基础,每次执行 docker run 的时候都会指定哪个镜像作为容器运行的基础.在之前的例子中,我们所使用的都是来自于 Docker Hub 的 ...