Description

Astronomers often examine star maps where stars are represented by points on a plane and each star has Cartesian coordinates. Let the level of a star be an amount of the stars that are not higher and not to the right of the given star. Astronomers want to know the distribution of the levels of the stars. 

For example, look at the map shown on the figure above. Level of the star number 5 is equal to 3 (it's formed by three stars with a numbers 1, 2 and 4). And the levels of the stars numbered by 2 and 4 are 1. At this map there are only one star of the level 0, two stars of the level 1, one star of the level 2, and one star of the level 3.

You are to write a program that will count the amounts of the stars of each level on a given map.

 
  题目就是求每个星星的等级,然后统计某个等级的有几个星星,等级的话就是左下边的星星的个数。
  把星星排序,从左到右,一次统计每个星星,把在他左边的加入二叉树,然后查找当前星星下面的就好了。
 
代码如下:

// ━━━━━━神兽出没━━━━━━
// ┏┓ ┏┓
// ┏┛┻━━━━━━━┛┻┓
// ┃ ┃
// ┃ ━ ┃
// ████━████ ┃
// ┃ ┃
// ┃ ┻ ┃
// ┃ ┃
// ┗━┓ ┏━┛
// ┃ ┃
// ┃ ┃
// ┃ ┗━━━┓
// ┃ ┣┓
// ┃ ┏┛
// ┗┓┓┏━━━━━┳┓┏┛
// ┃┫┫ ┃┫┫
// ┗┻┛ ┗┻┛
//
// ━━━━━━感觉萌萌哒━━━━━━ // Author : WhyWhy
// Created Time : 2015年07月17日 星期五 14时44分13秒
// File Name : 1195.cpp #include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h> using namespace std; const int MaxN=; int C[MaxN][MaxN];
int N; inline int lowbit(int x)
{
return x&(-x);
} void add(int x,int y,int d)
{
int t; while(x<=N)
{
t=y; while(t<=N)
{
C[x][t]+=d;
t+=lowbit(t);
} x+=lowbit(x);
}
} int query(int x,int y)
{
int ret=;
int t; while(x>)
{
t=y; while(t>)
{
ret+=C[x][t];
t-=lowbit(t);
} x-=lowbit(x);
} return ret;
} int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout); int a,b,c,d,e; while()
{
scanf("%d",&a); if(a==)
{
scanf("%d %d %d",&b,&c,&d);
add(b+,c+,d);
}
else if(a==)
{
scanf("%d %d %d %d",&b,&c,&d,&e);
printf("%d\n",query(d+,e+)-query(d+,c)-query(b,e+)+query(b,c));
}
else if(a==)
{
scanf("%d",&N);
memset(C,,sizeof(C));
}
else
break;
} return ;
}

(简单) POJ 2352 Stars,Treap。的更多相关文章

  1. poj 2352 Stars 数星星 详解

    题目: poj 2352 Stars 数星星 题意:已知n个星星的坐标.每个星星都有一个等级,数值等于坐标系内纵坐标和横坐标皆不大于它的星星的个数.星星的坐标按照纵坐标从小到大的顺序给出,纵坐标相同时 ...

  2. POJ 2352 Stars(线段树)

    题目地址:id=2352">POJ 2352 今天的周赛被虐了. . TAT..线段树太渣了..得好好补补了(尽管是从昨天才開始学的..不能算补...) 这题还是非常easy的..维护 ...

  3. POJ 2352 Stars(树状数组)

    Stars Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 30496   Accepted: 13316 Descripti ...

  4. 【树状数组】POJ 2352 Stars

    /** * @author johnsondu * @time 2015-8-22 * @type Binary Index Tree * ignore the coordinate of y and ...

  5. hdu 1541/poj 2352:Stars(树状数组,经典题)

    Stars Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submi ...

  6. POJ 2352 Stars(HDU 1541 Stars)

    Stars Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 41521   Accepted: 18100 Descripti ...

  7. [POJ] 2352 Stars [线段树区间求和]

    Stars Description Astronomers often examine star maps where stars are represented by points on a pla ...

  8. POJ 2352 Stars(树状数组)题解

    Language:Default Stars Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 52268 Accepted: 22 ...

  9. POJ 2352 stars (树状数组入门经典!!!)

    Stars Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 54352   Accepted: 23386 Descripti ...

随机推荐

  1. MyBatis SQL配置文件中使用#{}取值为null时却不报错的解决方案。

    原因是因为#{kh_id} 这个参数名为小写,我之前写成了大写{#KH_ID}所以取不到值

  2. git 查看当前与上一次version的差异

    http://stackoverflow.com/questions/9903541/finding-diff-between-current-and-last-versions up vote47d ...

  3. python gui编程

    1.准备工作 下载PyCharm 3.4(选择他的原因:1.有破解版,2.它的默认风格是PEB风格,一旦不符合PEB风格就会有提示) 下载并且安装界面设计工具wxFormBuilder 给python ...

  4. OpenGL------显示列表

    我们已经知道,使用OpenGL其实只要调用一系列的OpenGL函数就可以了.然而,这种方式在一些时候可能导致问题.比如某个画面中,使用了数千个多边形来表现一个比较真实的人物,OpenGL为了产生这数千 ...

  5. dump文件生成与调试(VS2008)

    总结一下dump文件生成和调试的方法: 1:用SetUnhandledExceptionFilter捕获未处理的异常,包含头文件<windows.h>.函数原型为: LPTOP_LEVEL ...

  6. GameUnity 2.0 文档(四) 网格+四叉树 最优碰撞检测

    在写之前,必须对 前一篇文档补充一下. Camera2DAngle类是 摄像机旋转 2d人物360度,PlayerMove是人物移动. 这两个类 都可以 360 °  场景旋转人物也跟着旋转. 但不能 ...

  7. JS取非行间样式

    <title>无标题文档</title> <style> #div1{width:200px;height:200px; background:red;} < ...

  8. HDU 4635 Strongly connected(强连通分量缩点+数学思想)

    题意:给出一个图,如果这个图一开始就不是强连通图,求出最多加多少条边使这个图还能保持非强连通图的性质. 思路:不难想到缩点转化为完全图,然后找把它变成非强连通图需要去掉多少条边,但是应该怎么处理呢…… ...

  9. mysql HA-keepalived

    关于MySQL-HA,目前有多种解决方案,比如heartbeat.drbd.mmm.共享存储,但是它们各有优缺点.heartbeat.drbd配置较为复杂,需要自己写脚本才能实现MySQL自动切换,对 ...

  10. PHPstorm端口配置问题