博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
(简单) POJ 2352 Stars,Treap。
阅读量:4357 次
发布时间:2019-06-07

本文共 2388 字,大约阅读时间需要 7 分钟。

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 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;const int MaxN=1100;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=0; int t; while(x>0) { t=y; while(t>0) { 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(1) { scanf("%d",&a); if(a==1) { scanf("%d %d %d",&b,&c,&d); add(b+1,c+1,d); } else if(a==2) { scanf("%d %d %d %d",&b,&c,&d,&e); printf("%d\n",query(d+1,e+1)-query(d+1,c)-query(b,e+1)+query(b,c)); } else if(a==0) { scanf("%d",&N); memset(C,0,sizeof(C)); } else break; } return 0;}
View Code

 

转载于:https://www.cnblogs.com/whywhy/p/4654672.html

你可能感兴趣的文章
Spring Boot (11) mybatis 关联映射
查看>>
macOS 下安装tomcat
查看>>
字符串格式化复习笔记
查看>>
c++ 宏定义调用不定参数的函数
查看>>
动态规划典型例题--背包问题九讲
查看>>
Qt之QHeaderView自定义排序(终极版)
查看>>
python----logging
查看>>
LBP特征 学习笔记
查看>>
与TIME_WAIT相关的几个内核参数修改测试讨论结论
查看>>
webpack构建react应用三:使用webpack Loaders 模块加载器(一)
查看>>
Java JDBC
查看>>
走势终完美 --执子之手
查看>>
补全左括号
查看>>
javascript中关于坐标 大小 的描述
查看>>
8086CPU各寄存器的用途
查看>>
AngularJs中,如何在render完成之后,执行Js脚本
查看>>
Nginx 防盗链
查看>>
如何讓Android系統顯示CJK擴展區漢字
查看>>
Android 下拉选择绑定Value和Text值
查看>>
HTML+CSS小结
查看>>