2464 -- Brownie Points II

Problem - 1156

  hdu分类线段树的题。题意是,给出一堆点的位置,stan和ollie玩游戏,stan通过其中一个点画垂线,ollie通过在垂线上的点画一条平行线。他们的得分是stan在一三象限中有多少点,ollie在二四象限中共有多少点。在平行线和垂线的点不算任何人的。

  开始的时候以为暴力二维线段树,结果发现点的数目也太庞大了。后来想了一想,只是统计这么几个区域,逐个插点就可以的嘛。用一个树状数组存下y坐标中相应位置的点的个数,向前向后做两次差点即可!

  错了一次忘记将答案unique,然后就AC了。

代码及debug的数据如下:

 #include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map> using namespace std; const int N = ;
inline int lowbit(int x) { return (-x) & x;}
struct BIT {
int c[N];
void init() { memset(c, , sizeof(c));}
void insert(int x) { x += ; for (int i = x; i < N; i += lowbit(i)) c[i]++;}
int query(int x) { int ret = ; for ( ; x > ; x -= lowbit(x)) ret += c[x]; return ret;}
int query(int l, int r) { if (l > r) return ; l += , r += ; return query(r) - query(l - );}
} bit; typedef pair<int, int> PII;
PII sc[N], pt[N], buf[N];
int y[N];
map<int, int> yid;
const int INF = 0x7fffffff; int main() {
// freopen("in", "r", stdin);
int n;
while (~scanf("%d", &n) && n) {
memset(sc, , sizeof(sc));
for (int i = ; i < n; i++) {
scanf("%d%d", &pt[i].first, &pt[i].second);
y[i] = pt[i].second;
}
sort(y, y + n);
sort(pt, pt + n);
int m = unique(y, y + n) - y;
for (int i = ; i < m; i++) yid[y[i]] = i;
bit.init();
for (int i = , top = -; i < n; i++) {
if (i && pt[i - ].first != pt[i].first) {
while (~top) bit.insert(yid[buf[top--].second]);
// cout << "pop! " << i << endl;
}
buf[++top] = pt[i];
sc[i].first += bit.query(, yid[pt[i].second] - );
sc[i].second += bit.query(yid[pt[i].second] + , m - );
}
// for (int i = 0; i < n; i++) cout << sc[i].first << ' '; cout << endl;
// for (int i = 0; i < n; i++) cout << sc[i].second << ' '; cout << endl;
bit.init();
for (int i = n - , top = -; i >= ; i--) {
if (i != n - && pt[i + ].first != pt[i].first) {
while (~top) bit.insert(yid[buf[top--].second]);
// cout << "pop~ " << i << endl;
}
buf[++top] = pt[i];
sc[i].first += bit.query(yid[pt[i].second] + , m - );
sc[i].second += bit.query(, yid[pt[i].second] - );
}
// for (int i = 0; i < n; i++) cout << sc[i].first << ' '; cout << endl;
// for (int i = 0; i < n; i++) cout << sc[i].second << ' '; cout << endl;
vector<int> tmp, best;
int fi = , se, mx = -INF;
sc[n] = PII(-, -);
while (fi < n) {
se = fi;
while (pt[fi].first == pt[se].first) se++;
int tmx = INF;
// cout << fi << ' ' << se << endl;
for (int i = fi; i < se; i++) {
if (tmx > sc[i].first) {
tmx = sc[i].first;
tmp.clear();
tmp.push_back(sc[i].second);
} else if (tmx == sc[i].first) tmp.push_back(sc[i].second);
}
fi = se;
if (mx < tmx) {
mx = tmx;
best = tmp;
} else if (mx == tmx) {
for (int i = , sz = tmp.size(); i < sz; i++) {
best.push_back(tmp[i]);
}
}
}
// cout << mx << ' ' << best.size() << endl;
sort(best.begin(), best.end());
printf("Stan: %d; Ollie:", mx);
int t = (int) (unique(best.begin(), best.end()) - best.begin());
while (best.size() > t) best.pop_back();
for (int i = , sz = best.size(); i < sz; i++) cout << ' ' << best[i]; cout << ';' << endl;
}
return ;
}

——written by Lyon

hdu 1156 && poj 2464 Brownie Points II (BIT)的更多相关文章

  1. POJ - 2464 Brownie Points II 【树状数组 + 离散化】【好题】

    题目链接 http://poj.org/problem?id=2464 题意 在一个二维坐标系上 给出一些点 Stan 先画一条过一点的水平线 Odd 再画一条 过Stan那条水平线上的任一点的垂直线 ...

  2. POJ 2464 Brownie Points II (树状数组,难题)

    题意:在平面直角坐标系中给你N个点,stan和ollie玩一个游戏,首先stan在竖直方向上画一条直线,该直线必须要过其中的某个点,然后ollie在水平方向上画一条直线,该直线的要求是要经过一个sta ...

  3. POJ 2464 Brownie Points II(树状数组)

    一开始还以为对于每根竖线,只要与过了任意一点的横线相交都可以呢,这样枚举两条线就要O(n^2),结果发现自己想多了... 其实是每个点画根竖线和横线就好,对于相同竖线统计(一直不包含线上点)右上左下总 ...

  4. POJ 2464 Brownie Points II --树状数组

    题意: 有点迷.有一些点,Stan先选择某个点,经过这个点画一条竖线,Ollie选择一个经过这条直接的点画一条横线.Stan选这两条直线分成的左下和右上部分的点,Ollie选左上和右下部分的点.Sta ...

  5. UVA10869 - Brownie Points II(线段树)

    UVA10869 - Brownie Points II(线段树) 题目链接 题目大意:平面上有n个点,Stan和Ollie在玩游戏,游戏规则是:Stan先画一条竖直的线作为y轴,条件是必需要经过这个 ...

  6. UVA 10869 - Brownie Points II(树阵)

    UVA 10869 - Brownie Points II 题目链接 题意:平面上n个点,两个人,第一个人先选一条经过点的垂直x轴的线.然后还有一个人在这条线上穿过的点选一点作垂直该直线的线,然后划分 ...

  7. Day6 - E - Brownie Points II POJ - 2464

    Stan and Ollie play the game of Odd Brownie Points. Some brownie points are located in the plane, at ...

  8. HDOJ-1156 Brownie Points II 线段树/树状数组(模板)

    http://acm.hdu.edu.cn/showproblem.php?pid=1156 在一张二位坐标系中,给定n个点的坐标,玩一个划线游戏(线必须穿过点),Stan先手画一条垂直的线,然后Ol ...

  9. Hdu 1156

    题目链接 Brownie Points II Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java ...

随机推荐

  1. js里面的this指向

    1.  this是动态绑定的,或者说是在代码运行期绑定而不是在书写期 function fire () { console.log(this.a) } var obj = { a: 1, fire: ...

  2. python内置模块大全 processon

    https://www.processon.com/view/link/5b4ee15be4b0edb750de96ac#map

  3. kubernetes1.4新特性:支持两种新的卷插件

    背景介绍 在Kubernetes中卷的作用在于提供给POD持久化存储,这些持久化存储可以挂载到POD中的容器上,进而给容器提供持久化存储. 从图中可以看到结构体PodSpec有个属性是Volumes, ...

  4. 第二章 使用eclipse创建web项目

    一.启动eclipse,点击菜单栏中的File->New->Dynamic Web Project新建一个动态网站项目 二.设置项目名称和运行服务器 三.点击next,进行下一步 四.如图 ...

  5. 2019-8-31-dotnet-方法名-To-和-As-有什么不同

    title author date CreateTime categories dotnet 方法名 To 和 As 有什么不同 lindexi 2019-08-31 16:55:58 +0800 2 ...

  6. Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第六章:在Direct3D中绘制

    原文:Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第六章:在Direct3D中绘制 代码工程地址: https://gi ...

  7. 笔记:字体大小的几种不同的格式px,em,rem

    px px像素(Pixel),相对长度单位,像素px是相对于显示器屏幕分辨率而言的.(引自CSS2.0手册) 譬如,Windows的用户所使用的分辨率一般是96像素/英寸. 而MAC的用户所使用的分辨 ...

  8. @codeforces - 444A@ DZY Loves Physics

    目录 @description@ @solution@ @accepted code@ @details@ @description@ 给定一个 n 点 m 边的图,边有边权,点有点权. 找到一个连通 ...

  9. PHP程序连接Redis报read error on connection问题

    线上PHP程序动不动就报PHP Fatal error: Uncaught RedisException: read error on connection错误,就是连接Redis在那么1秒钟有问题, ...

  10. c50决策树借款风险

    Decision Trees/ Machine Learning Durga Gaddam August 29, 2016 Objective: The objective of the articl ...