HDU 1541 Stars (树状数组)
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.
point of the plane. Stars are listed in ascending order of Y coordinate. Stars with equal Y coordinates are listed in ascending order of X coordinate.
5
1 1
5 1
7 1
3 3
5 5
1
2
1
1
0
直接统计不大于当前数的个数,然后hash记录。
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <set>
#include <stack>
#include <cctype>
#include <algorithm>
#define lson o<<1, l, m
#define rson o<<1|1, m+1, r
using namespace std;
typedef long long LL;
const int mod = 99999997;
const int MAX = 0x3f3f3f3f;
const int maxn = 15050;
const int N = 32005;
int n, a, b;
int c[N], ans[maxn];
int main()
{
while(~scanf("%d", &n)) {
memset(c, 0, sizeof(c));
memset(ans, 0, sizeof(ans));
int k = 0;
for(int i = 1; i <= n; i++) {
scanf("%d%d", &a, &b); a++;
int sum = 0;
for(int j = a; j > 0; j -= j&(-j)) sum += c[j];
for(int j = a; j <= N; j += j&(-j)) c[j]++;
ans[sum]++;
}
for(int i = 0; i < n; i++) printf("%d\n", ans[i]);
}
return 0;
}
版权声明:本文博主原创文章,博客,未经同意不得转载。
HDU 1541 Stars (树状数组)的更多相关文章
- POJ 2352 && HDU 1541 Stars (树状数组)
一開始想,总感觉是DP,但是最后什么都没想到.还暴力的交了一发. 然后開始写线段树,结果超时.感觉自己线段树的写法有问题.改天再写.先把树状数组的写法贴出来吧. ~~~~~~~~~~~~~~~~~~~ ...
- hdu 1541 (基本树状数组) Stars
题目http://acm.hdu.edu.cn/showproblem.php?pid=1541 n个星星的坐标,问在某个点左边(横坐标和纵坐标不大于该点)的点的个数有多少个,输出n行,每行有一个数字 ...
- HDU 1541 STAR(树状数组)
Stars Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Subm ...
- Stars(树状数组)
http://acm.hdu.edu.cn/showproblem.php?pid=1541 Stars Time Limit: 2000/1000 MS (Java/Others) Memor ...
- hdu1541 Stars 树状数组
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1541 题目大意就是统计其左上位置的星星的个数 由于y已经按升序排列,因此只用按照x坐标生成一维树状数组 ...
- HDU 2838 (DP+树状数组维护带权排序)
Reference: http://blog.csdn.net/me4546/article/details/6333225 题目链接: http://acm.hdu.edu.cn/showprobl ...
- HDU 2689Sort it 树状数组 逆序对
Sort it Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Sub ...
- POJ-2352 Stars 树状数组
Stars Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 39186 Accepted: 17027 Description A ...
- Stars(树状数组或线段树)
Stars Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 37323 Accepted: 16278 Description A ...
- hdu 4046 Panda 树状数组
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4046 When I wrote down this letter, you may have been ...
随机推荐
- java中取得上下文路径的方法
1.request.getContextPath(); 获得web根的上下文环境 如 /tree tree是web项目的root context 2.可以在servlet的init方法里 String ...
- SecureCRT学习之道:SecureCRT常用快捷键设置与字体设置方法
1:如果不想每次登陆都输入密码,可以在你打开的session里邮件session option->login action 选中automate logon 双击ogin 和assword分别输 ...
- Broadcast Receiver注意事项
静态登记 <receiver android:name=".MyReceiver" android:enabled="true"> <inte ...
- AC automation 模板
/* 1.对n个字符串构造tire树 insertWord(node *root, char *word); 2.bfs构造fail指针 makeFail(node *root); 3.基于以上两点的 ...
- simplePagination API
simplePagination API simplePagination.js 一个简单的jQuery分页插件,主题和Bootstrap支持CSS 3 分页button样式 "light- ...
- POJ训练计划2418_Hardwood Species(Trie树)
解题报告 Tire树. #include <iostream> #include <cstring> #include <cstdio> #include < ...
- Android开发有用技巧:推断当前系统语言版本号
Locale locale = getResources().getConfiguration().locale; String language = locale.getLanguage(); 以上 ...
- cocos2d-x适配多分辨率
现在用的2d-x版本是2.1.1.现在的项目要求是iphone ,iphone Retina,ipad和ipad Retina都有各自的路径来存放各自需要的资源.在AppDelegate的 appli ...
- 重新想象 Windows 8 Store Apps (24) - 文件系统: Application Data 中的文件操作, Package 中的文件操作, 可移动存储中的文件操作
原文:重新想象 Windows 8 Store Apps (24) - 文件系统: Application Data 中的文件操作, Package 中的文件操作, 可移动存储中的文件操作 [源码下载 ...
- Storm具体的解释(二)、成为第一Storm申请书
在全面介绍Storm之前,我们首先通过简单的Demo让我们来看看什么是整体感觉Storm. Storm执行模式: 本地模式(Local Mode): 即Topology(相当于一个任务,兴许 ...