Brownie Points II | |
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. | |
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; | |
https://vjudge.net/problem/17705/origin | |
参考文章:https://blog.csdn.net/libin56842/article/details/46582685 | |
这道题没怎么看懂,看别人的博客: 题意:平面上有若干点,stan通过一个点划了一条直线,ollie通过在这条垂直直线上的点作了一条水平线,平面被分成4个象限,定义stan获得的分数为1,3象限的点的数量,ollie获得的分数为2,4象限上的点的数量,线上的点不归任何人所有。两人都采用最优的策略使自己获得的点数最大。由于stan的选择具有主动权,为了对自己有利,求stan所能够获得的最小的可能的分数最大,输出该分数,并输出ollie可能的分数。 | |
思路:首先分析可以得到:stan画的线上如果没有其他点,那么ollie的选择只有一个。如果有多个点,ollie会选择自己分数高的点,如果相同,选择stan分数低的点。 | |
实现: 定义right[i]的,第i个正右方向,left[i],第i个负左方向,up[i],第i个正上方向,down[i]第i个负下方向,并且定义:TR,TL,BL,BR为第一象限的点。 首先对y升序排序(y相同按x升序排序),获得对large(反向),left(正向),right(反向)的统计。由于题目中没有明确的坐标范围,因此需要对点进行离散化,并且排序操作已经已经使得一个点对的一维操作已经有序,那么我们只要离散此时的y值,得到原来的下标对应的按x排序后的下标。为了得到up,down的统计值,然后再对x升序排序(x相同升序y)。如此就有我们所需要的所有数据。设定一条垂直线,水平从第一个点向右移动,得到最小的没有被访问过的点的横坐标的原来的编号对应的通过y离散化后的编号,,用树状数组维护左下的点数,计算并统计更新答案。 | |
|