HDOJ-1156 Brownie Points II 线段树/树状数组(模板)
http://acm.hdu.edu.cn/showproblem.php?pid=1156
在一张二位坐标系中,给定n个点的坐标,玩一个划线游戏(线必须穿过点),Stan先手画一条垂直的线,然后Ollie画一条水平的线(要求要穿过Stan那条线所穿过的某个点)。划分后,左上和右下点数是Ollie 的得分,左下和右上是Stan的得分。求Stan在保证最低得分(即不论Ollie后手怎么划,Stan最少能的的分数)最高,并给出基于符合的先手划法,Ollie后手的各种划线的得分(需要去重),升序输出。
这里可以发现,每次划分等同于枚举以某个点为原点,求一次局面,不同的局面分类到x轴坐标中,每个坐标中的局面集合求最小值,所有x轴坐标分类求最大值即求出了最低最大划法。
#include <iostream>
#include <cstring>
#include <string>
#include <queue>
#include <vector>
#include <set>
#include <stack>
#include <cmath>
#include <cstdio>
#include <map>
#include <algorithm>
using namespace std;
struct node
{
int x, y;
}p[];
bool cmpx(node a, node b)
{
if (a.x == b.x) return a.y < b.y;
return a.x < b.x;
}
const int N = ;
map<int, int> mpx, mpy;
int st[N];
int tre[N];
int ans[N];
int lowbit(int k)
{
return k&-k;
}
int query(int k)
{
int rec = ;
while (k)
{
rec += tre[k];
k -= lowbit(k);
}
return rec;
}
void add(int k)
{
while (k <= N)
{
tre[k]++;
k += lowbit(k);
}
}
bool cmp(node a, int b)
{
return a.x < b;
}
int main() {
cin.sync_with_stdio(false);
int n;
while (cin>>n)
{
if (n == ) break;
mpx.clear(), mpy.clear();
queue<node> wq;
fill(tre, tre + N, );
fill(ans, ans + N, );
for (int i = ; i < n; i++)
cin >> p[i].x>>p[i].y,mpx[p[i].x]++,mpy[p[i].y]++,st[i]=p[i].y;
sort(st, st + n);
int len = unique(st, st + n) - st;
sort(p, p + n, cmpx); for (int i = ; i < n; i++)
{
while (!wq.empty())
{
node ad = wq.front();
if (ad.x < p[i].x) add(upper_bound(st, st + len, ad.y) - st + ),wq.pop();
else break;
}
int py = upper_bound(st, st + len, p[i].y)-st+;
ans[i] += query(py-);
wq.push(p[i]);
}
while (!wq.empty()) wq.pop();
fill(tre, tre + , );
for (int i = n-; i >= ; i--)
{
while (!wq.empty())
{
node ad = wq.front();
if (ad.x > p[i].x) add(len+st-upper_bound(st, st + len, ad.y) + ),wq.pop();
else break;
}
int py = len + st - upper_bound(st, st + len, p[i].y) + ;
ans[i] += query(py-);
wq.push(p[i]);
}
map<int, int> getMi;
for (int i = ; i < n; i++)
{
if (getMi.find(p[i].x) == getMi.end()) getMi[p[i].x] = ans[i];
else getMi[p[i].x] = min(getMi[p[i].x], ans[i]);
}
map<int, int>::iterator mxit = getMi.end();
for (map<int, int>::iterator it = getMi.begin(); it != getMi.end(); it++)
{
if (mxit == getMi.end())
mxit = it;
else if (mxit->second < it->second)
mxit = it;
}
cout << "Stan: " << mxit->second << "; Ollie:";
set<int> rpy;
for (int i = ; i < n; i++)
if (getMi[p[i].x]==ans[i]&&ans[i] == mxit->second)
rpy.insert(n - ans[i] - mpx[p[i].x] - mpy[p[i].y] + ); for (set<int>::iterator it = rpy.begin(); it != rpy.end(); it++)
{
cout << ' ' << *it;
}
cout << ";" << endl;
}
return ;
}
HDOJ-1156 Brownie Points II 线段树/树状数组(模板)的更多相关文章
- UVA10869 - Brownie Points II(线段树)
UVA10869 - Brownie Points II(线段树) 题目链接 题目大意:平面上有n个点,Stan和Ollie在玩游戏,游戏规则是:Stan先画一条竖直的线作为y轴,条件是必需要经过这个 ...
- UVA 10869 - Brownie Points II(树阵)
UVA 10869 - Brownie Points II 题目链接 题意:平面上n个点,两个人,第一个人先选一条经过点的垂直x轴的线.然后还有一个人在这条线上穿过的点选一点作垂直该直线的线,然后划分 ...
- hdu 1156 && poj 2464 Brownie Points II (BIT)
2464 -- Brownie Points II Problem - 1156 hdu分类线段树的题.题意是,给出一堆点的位置,stan和ollie玩游戏,stan通过其中一个点画垂线,ollie通 ...
- HDU 1166 线段树模板&树状数组模板
HDU1166 上好的线段树模板&&树状数组模板 自己写的第一棵线段树&第一棵树状数组 莫名的兴奋 线段树: #include <cstdio> using nam ...
- HDU 1166 敌兵布阵(线段树/树状数组模板题)
敌兵布阵 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submi ...
- luogu3368树状数组模板2
题目链接:https://www.luogu.org/problemnew/show/P3368 题意:与模板1不同的是这题的操作是树状数组并不在行的区间更新和单点查找,如果按照模板1那样写肯定会T. ...
- 树状数组模板(pascal) 洛谷P3374 【模板】树状数组1
题目描述 如题,已知一个数列,你需要进行下面两种操作: 1.将某一个数加上x 2.求出某区间每一个数的和 输入输出格式 输入格式: 第一行包含两个整数N.M,分别表示该数列数字的个数和操作的总个数. ...
- POJ 2464 Brownie Points II(树状数组)
一开始还以为对于每根竖线,只要与过了任意一点的横线相交都可以呢,这样枚举两条线就要O(n^2),结果发现自己想多了... 其实是每个点画根竖线和横线就好,对于相同竖线统计(一直不包含线上点)右上左下总 ...
- POJ 2464 Brownie Points II --树状数组
题意: 有点迷.有一些点,Stan先选择某个点,经过这个点画一条竖线,Ollie选择一个经过这条直接的点画一条横线.Stan选这两条直线分成的左下和右上部分的点,Ollie选左上和右下部分的点.Sta ...
随机推荐
- Python3 tkinter基础 Button command 单击按钮 在console中打印文本
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- memalign的作用【转】
本文转载自:https://blog.csdn.net/lvwx369/article/details/41726415 转自:http://hi.baidu.com/narshben/item/ca ...
- Get and Set Column/Row Names for Data Frames
row.names(x)row.names(x) <- value rownames(x, do.NULL = TRUE, prefix = "row") rownames( ...
- Java程序运行机制及开发环境
Java既是编译型语言,又是解释型语言 java源文件首先需要通过javac编译生成后缀名为.class的字节码文件(与平台无关,只面向JVM),然后使用Java虚拟机将字节码解释成特定平台上的机器码 ...
- [echarts] - echarts量化比较图表类型解析
https://echarts.baidu.com/examples/editor.html?c=watermark <!DOCTYPE html> <!--用作两种货品的参数对比- ...
- 3、My Scripts
.用for循环批量修改文件扩展名(P240) .使用专业改名命令rename来实现 .通过脚本实现sshd.rsyslog.crond.network.sysstat服务在开机时自动启动(P244) ...
- Nginx教程---01.Nginx入门
create by 三七二十一 LZ参考视频(年代久远,但万变不离其宗): 链接:https://pan.baidu.com/s/1O_MmN0c3ckM6vbk08n8Qkg 密码:z9zr 01_ ...
- Appium典型问题处理
1. http://ask.testfan.cn/article/902 Appium 服务端安装-windows2. http://ask.testfan.cn/article/1078 最新版本a ...
- STL_string.ZC
1.转成 小写/大写 #include <algorithm>using namespace std; // 转成小写transform(_strAttrNameG.begin(), _s ...
- [转][JSBSim]使用VS2015编译JSBSim
转自csdn原文:https://blog.csdn.net/yu_lei_/article/details/81463187 请大家去看原文,原文有图片和资源,本文仅供本人参考 权威参考:http: ...