首页 技术 正文
技术 2022年11月14日
0 收藏 652 点赞 3,719 浏览 1753 个字

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. 
(简单) POJ 2352 Stars,Treap。
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 ;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,110
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,584
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,431
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,202
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,837
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,920