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. 2018-2-13-C#-相对路径转绝对路径

    title author date CreateTime categories C# 相对路径转绝对路径 lindexi 2018-2-13 17:23:3 +0800 2018-2-13 17:23 ...

  2. System V启动脚本启动的服务

    /etc/rc.d/init.d/目录下的内容如下:这些常用的服务器都是System v的服务,要控制System V 的服务,我们可以使用以下命令 #/etc/rc.d/init.d/script  ...

  3. 洛谷P1084 [NOIP2012提高组Day2T3]疫情控制

    P1084 疫情控制 题目描述 H 国有 n 个城市,这 n 个城市用 n-1 条双向道路相互连通构成一棵树,1 号城市是首都,也是树中的根节点. H 国的首都爆发了一种危害性极高的传染病.当局为了控 ...

  4. 怎么让一个不定宽高的div垂直水平居中?

    方法一:使用CSS3 transform 父盒子设置:position:relative; div设置:position:absolute;transform:translate(-50%,-50%) ...

  5. Django项目:CRM(客户关系管理系统)--06--03PerfectCRM创建基本数据01

    os.path.join(BASE_DIR, 'DBadd/DBadd_templates'), """ Django settings for PerfectCRM p ...

  6. jQuery 图片上传

    1. 概述 1.1 说明 在一些前后端不分离的项目中,经常有一些需要把文件或者图片上传的功能,故记录此代码以便后期使用. 1.2 要求 1.上传,10M以内,限bmp,jpg,png,jpeg等图片格 ...

  7. Direct2D 第2篇 绘制椭圆

    原文:Direct2D 第2篇 绘制椭圆 #include <windows.h> #include <d2d1.h> #include <d2d1helper.h> ...

  8. vue-waterfall2 基于Vue.js 瀑布流组件

    vue-waterfall2 1.宽度自适应,数据绑定特效(适用于上拉加载更多) 2.自定义程度高 3.使用极为简便,适用于PC/移动端 4.提供resize(强制刷新布局-适用于下拉刷新)/mix( ...

  9. NFS实现(双httpd + php-fpm + nfs + mysql 搭建discuz论坛)的方法

    NFS相关介绍 一.NFS简介 1. NFS(Network File System):NFS是一个文件共享协议, 也是是在类Unix系统中在内核中实现的文件系统. 2. 起源:最早是由SUN公司研发 ...

  10. 用SpannableString来设置一个textview的各种样式

    通常情况下,textview 设置文本的样式很单一,为了满足某种需求可以使用SpannableString来设置文本字体大小.颜色.超链接等属性. xml就一个TextView所以就不在给出了,直接看 ...