POJ 2352
来源:互联网 发布:2016广电禁止网络电视 编辑:程序博客网 时间:2024/06/06 00:09
题目大意:
在坐标上有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小)。
所以,需要找到一种数据结构来记录所有星星的x值,方便的求出所有值为0~x的星星总数量。
树状数组和线段树都是很适合处理这种问题。
#include <cstdio>#include <iostream>#include <cstring>#include <string>#include <cstdlib>#include <algorithm>#include <cmath>#include <set>#include <list>#include <queue>using namespace std;#define L(i) i<<1#define R(i) i<<1|1#define INF 0x3f3f3f3f#define pi acos(-1.0)const int N = 100005;const double eps = 1e-10;int c[32100],level[32100],n;void update(int x,int num){ while(x <= 32100) { c[x] += num; x += x&(-x); }}int getsum(int x){ int s = 0; while(x) { s += c[x]; x -= x&(-x); } return s;}int main(){ while(~scanf("%d",&n)) { int x,y; memset(level, 0, sizeof(level)); memset(c, 0, sizeof(c)); for(int i=0; i<n; ++i) { scanf("%d%d",&x,&y); ++x; level[getsum(x)]++; update(x,1); } for(int i=0; i<n; ++i) printf("%d\n",level[i]); } return 0;}
0 0
- poj 2352
- poj 2352
- poj 2352
- poj 2352
- poj 2352
- poj 2352
- poj 2352
- poj 2352
- poj 2352
- poj-2352
- POJ 2352
- poj 2352
- poj-2352
- poj 2352
- poj 2352
- POJ 2352
- poj 2352
- POJ 2352 STARS
- 8_12 ./char_at_a_time
- 数据结构实践——字符串加密
- 查找树的子结构
- 第九周--压缩存储的对称矩阵的运算
- 项目4-字符串加密
- POJ 2352
- 第9周 项目2-对称矩阵的压缩存储及基本运算
- 【bzoj2180】【最小直径生成树】【图的绝对中心】
- 【Android成长之路】最常用和最难用的控件——ListView的浅谈(ListView 的简单用法)
- 操作系统中长期调度、中期调度和短期调度之间的区别
- Codeforces 590B Chip 'n Dale Rescue Rangers
- Navicat 错误10061解决办法
- Windows热键注册(反汇编方法 查看win32api 原理)
- 2016搜狗公司研发工程师笔试题