POJ 2352Stars 树状数组
来源:互联网 发布:volatile 修饰数组 编辑:程序博客网 时间:2024/06/09 22:01
题目:http://poj.org/problem?id=2352
题意:给出一些星星的坐标,按y坐标升序给出,若y坐标相等按照x升序给出。每个星星有一个水平,就是这颗星星左下方的星星数目。输出所有水平的个数
思路:因为是按y坐标升序给出的,所以当前星星的左下方星星一定给出过了,忽略y坐标,也是小于等于当前星星x坐标的星星个数,可以用树状数组轻松求出
#include <iostream>#include <cstring>#include <cstdio>#include <algorithm>#include <vector>#include <cmath>using namespace std;typedef long long ll;const int N = 50010;int bit[N], level[N], n;void add(int i, int x){ while(i <= 50000) bit[i] += x, i += i & -i;}int sum(int i){ int s = 0; while(i > 0) s += bit[i], i -= i & -i; return s;}int main(){ int a, b; while(~ scanf("%d", &n)) { memset(bit, 0, sizeof bit); memset(level, 0, sizeof level); for(int i = 1; i <= n; i++) { scanf("%d%d", &a, &b); a++, b++; add(a, 1); int res = sum(a) - 1; //因为先更新后查询,所以其实把当前星星也算了进去,所以减去1 level[res]++; } for(int i = 0; i < n; i++) printf("%d\n", level[i]); } return 0;}
0 0
- POJ 2352 Stars 树状数组
- POJ 2352 Stars【树状数组】
- (树状数组) poj 2352 Stars
- POJ-2352-Stars-树状数组
- POJ 2352 Stars 树状数组
- POJ 2352 Stars 【树状数组】
- POJ 2352 Stars 树状数组
- POJ-2352 Stars【树状数组】
- POJ 2352 Stars 树状数组
- poj 2352 Stars 树状数组
- poj 2352 Stars 树状数组
- POJ:2352 Stars(树状数组)
- [树状数组]POJ 2352 Stars
- POJ-2352-Stars 树状数组
- Stars - POJ 2352 树状数组
- poj 2352 Stars 树状数组
- poj 2352 Stars (树状数组)
- POJ 2352 Stars【树状数组】
- POJ 1569 Myacm Triangles
- HDU 5806 NanoApe Loves Sequence Ⅱ
- hibernate 5.x 的schemaExport的用法
- 第16课:Scala implicits编程彻底实战及Spark源码鉴赏
- 测试一下:欢迎使用CSDN-markdown编辑器
- POJ 2352Stars 树状数组
- 11、CSS3动画
- 第二周项目三-----小试循环
- CSS——NO.5(格式化排版)
- ubuntu装jdk
- JSP传统标签开发
- 关于创业公司产品开发原则
- Intel IOMMU
- xampp 虚拟目录配置