POJ 2352 Stars(树状数组)
来源:互联网 发布:怎样用js做用户名验证 编辑:程序博客网 时间:2024/06/03 08:32
因为按照y排序的,所以只需要考虑x就可以了,树状数组的意思是有一个隐藏数组a[i],代表i点有没有点,如果i点有的话,c数组跟i有关的元素全部更新,然后sum(x)又是a数组从1到x相加,算出小于等于x的个数,那么相应的level要加1。
//// main.cpp// Richard//// Created by 邵金杰 on 16/8/20.// Copyright © 2016年 邵金杰. All rights reserved.//#include<iostream>#include<cstdio>#include<cstring>using namespace std;const int maxn=15000+10;const int INF=32000+10;int c[INF],level[maxn];int n;void add(int x){ while(x<=INF) { c[x]++; x+=(x&(-x)); }}int sum(int x){ int s=0; while(x) { s+=c[x]; x-=(x&(-x)); } return s;}int main(){ int x,y; while(scanf("%d",&n)!=EOF) { memset(c,0,sizeof(c)); memset(level,0,sizeof(level)); for(int i=0;i<n;i++) { scanf("%d%d",&x,&y); level[sum(x+1)]++; add(x+1); } 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 (树状数组!!)
- Stars (poj 2352 树状数组)
- POJ 2352 Stars(树状数组)
- POJ---2352-Stars(树状数组)
- POJ 2352 Stars (树状数组)
- POJ 2352 Stars(树状数组)
- POJ 2352 Stars(树状数组)
- POJ 2352 Stars(树状数组)
- POJ 2352 Stars(树状数组)
- POJ 2352 Stars (树状数组)
- java. long util io等 区别
- ContextLoaderListener作用详解
- 数据结构实验之排序三:bucket sort
- 黄阶低级 - 《 Java 核心》- 4.6 对象构造 - 修改0次
- 彻底理解webservice SOAP WSDL
- POJ 2352 Stars(树状数组)
- nyoj-1261-音痴又音痴的LT【思维】
- UVAlive 6623 Battle for Silver(暴力+思路)
- TCP-心跳
- Leetcode 385. Mini Parser
- QRCode生成二维码和解析二维码
- 数据结构实验之二叉树六:哈夫曼编码
- 使用wifi网卡笔记3---工具wpa_supplicant(STA模式)
- MAC OS 安装pip