poj 2352 Stars
来源:互联网 发布:淘宝优惠券宣传海报 编辑:程序博客网 时间:2024/06/13 14:12
题目大意:
在坐标上有n个星星,如果某个星星坐标为(x, y), 它的左下位置为:(x0,y0),x0<=x 且y0<=y。如果左下位置有a个星星,就表示这个星星属于level x
按照y递增,如果y相同则x递增的顺序给出n个星星,求出所有level水平的数量。
分析与总结:
因为输入是按照按照y递增,如果y相同则x递增的顺序给出的, 所以,对于第i颗星星,它的level就是之前出现过的星星中,横坐标x小于等于i星横坐标的那些星星的总数量(前面的y一定比后面的y小)。这是典型的树状数组的简单应用。要注意不能出现横坐标为0的情况
#include <queue>#include <cmath>#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>using namespace std;const int MAX = 32005;int c[MAX],level[MAX];int lowbit(int x){return x & (-x);}void add(int x){while(x < MAX){c[x]++;x += lowbit(x);}}int sum(int x){int res = 0;while(x > 0){res += c[x];x -= lowbit(x);}return res;}int main(){int n,x,y;while(scanf("%d",&n) == 1){memset(c, 0, sizeof(c));memset(level, 0, sizeof(level));for(int i=0; i<n; i++){scanf("%d%d",&x,&y);++x;level[sum(x)]++;add(x);}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
- POJ 2352 Stars
- POJ 2352 Stars
- poj 2352 Stars
- poj 2352 Stars
- ffmpeg开发指南
- 手机的音频口通信
- 【水题】Codeforces Round #289 509B Painting Pebbles
- WindowsError的错误代码详解
- 最常用的排序——快速排序
- poj 2352 Stars
- AE的空间查询功能
- java连接jdbc数据库
- 日期和时间函数
- 怎么把pdf文档内容转换成word
- php学习笔记之list()赋值问题及each()结合遍历
- VC++串口通信编程详解
- java连接JDBC代码
- Android ScrollView与ListView,GridView共存冲突解决方案