Stars
来源:互联网 发布:手机淘宝退款流程 编辑:程序博客网 时间:2024/06/05 15:14
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.
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.
51 15 17 13 35 5
12110
思路:y是按照升序的顺序排序的,所以可以直接忽略y,对x进行排序即可,树状数组种存贮的是每个值出现的次数
#include <cstdio>#include <cstring>using namespace std;#define N 32005int n,c[N],ans[N],x,y;int lowbit(int k){ return k&-k;}int sum(int x){ int ret=0; while(x>0) { ret+=c[x]; x-=lowbit(x); } return ret;}void add(int x,int d){ while(x<=N) { c[x]+=d; x+=lowbit(x); }}int main(){ int i,j,k; while(~scanf("%d",&n)) { memset(ans,0,sizeof(ans)); memset(c,0,sizeof(c)); for(i = 1; i<=n; i++) { scanf("%d%d",&x,&y); x++; ans[sum(x)]++; add(x,1); } for(i = 0; i<n; i++) printf("%d\n",ans[i]); } return 0;}
阅读全文
0 0
- stars
- Stars
- Stars
- Stars
- Stars
- Stars
- Stars
- Stars
- stars
- Stars
- Stars
- stars
- Stars
- Stars
- Stars
- 7stars
- PKU2352 stars
- hdu1541 Stars
- C语言逗号运算符用法
- 如何利用深度学习技术训练聊天机器人语言模型?
- hive从查询中获取数据插入到表或动态分区
- 关于java中的连等赋值问题(雷惊风)
- Spring--IoC--域属性的注入-使用spring注解
- Stars
- Java入侵检测(三)
- 设置单选框不可选,但可以传输数据
- linux下安装JDK
- cocos2dx 植物大战僵尸 5 塔基Terrain的更新
- 回归:逻辑回归 Logistic Regression
- dpkg的用法
- java对一个number进行倒置
- keil 的 配置向导 configuration wizard