HOJ Stars 2678
来源:互联网 发布:tensorflow helloword 编辑:程序博客网 时间:2024/06/05 20:27
这个题与poj的思路有点类似 点击打开poj Stars
#include <iostream>#include <cstring>#include <algorithm>using namespace std;const int MAXN = 1010;int c[MAXN][MAXN];struct Node{int x, y, z;}stars[15010];int cmp(Node a, Node b){if(a.z != b.z)return a.z < b.z;else if(a.y != b.y)return a.y < b.y;return a.x < b.x;}int lowbit( int x ){return x&(-x);}void UFset(int x, int y, int data){for(int i = x; i < MAXN; i += lowbit(i))for(int j = y; j < MAXN; j += lowbit(j))c[i][j] += data;}int GetSum(int x, int y){int sum = 0;for(int i = x; i > 0; i -= lowbit(i))for(int j = y; j > 0; j -= lowbit(j))sum += c[i][j];return sum;}int main(){int N;int i, x, y, z;int s[15010];while(scanf("%d", &N) != EOF){memset(stars, 0, sizeof(stars));memset(c, 0, sizeof(c));memset(s, 0, sizeof(s));for(i = 0; i < N; ++i){scanf("%d %d %d", &x, &y, &z);stars[i].x = x, stars[i].y = y, stars[i].z = z;}sort(stars, stars+N, cmp);for(i = 0; i < N; ++i){int level = GetSum(stars[i].x+1, stars[i].y+1);//之所以要加1,那是因为可能有星星的坐标重复s[level]++;UFset(stars[i].x+1, stars[i].y+1, 1);}for(i = 0; i < N-1; ++i)printf("%d ", s[i]);printf("%d\n", s[i]);}return 0;}
- HOJ 2678 Stars
- HOJ 2678 Stars
- HOJ Stars 2678
- HOJ 2678 stars
- [hoj 2678]Stars[二维树状数组]
- stars
- Stars
- Stars
- Stars
- Stars
- Stars
- Stars
- Stars
- stars
- Stars
- Stars
- stars
- Stars
- 片上总线Wishbone 学习(六)总线周期之操作发起
- jQuery学习之prop和attr的区别
- hdu3117(斐波那契数列+矩阵快速幂)
- 走走停停
- 类的各种成员函数在内存中是如何分配的?
- HOJ Stars 2678
- 移动互联网再理解:从比特世界向原子世界的回迁(虎嗅网)
- 回调函数中调用类中的非静态成员变量或非静态成员函数
- 一个引号造成的错误
- 几种任务调度的 Java 实现方法与比较
- PCEDM模型是哪些英文单词的缩写
- SQL中内连接和外连接
- 杭电2571(DP)。
- C++第12周项目1——某年的第几天