POJ 2352Stars 树状数组
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 42898 | Accepted: 18664 |
Description

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.
Input
Output
Sample Input
5
1 1
5 1
7 1
3 3
5 5
Sample Output
1
2
1
1
0
Hint
Source
代码:
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
const int MAXN=,MAXX=;
int c[MAXX];
int ans[MAXN];
int lowbit(int x)
{
return x&(-x);
}
void add(int i,int val)
{
for(i; i<=MAXX; i+=lowbit(i))
c[i]+=val;
}
int sum(int i)
{
int s=;
for(i; i>; i-=lowbit(i))
s+=c[i];
return s;
}
int main()
{
int i,n;
int x,y;
while(scanf("%d",&n)!=EOF)
{
memset(c,,sizeof(c));
memset(ans,,sizeof(ans));
for(i=; i<n; i++)
{
scanf("%d%d",&x,&y);
int temp=sum(x+);
ans[temp]++;
add(x+,);
}
for(i=; i<n; i++)
printf("%d\n",ans[i]);
}
return ;
}
树状数组
POJ 2352Stars 树状数组的更多相关文章
- POJ 3321 树状数组(+dfs+重新建树)
Apple Tree Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 27092 Accepted: 8033 Descr ...
- poj 2299 树状数组求逆序数+离散化
http://poj.org/problem?id=2299 最初做离散化的时候没太确定可是写完发现对的---由于后缀数组学的时候,,这样的思维习惯了吧 1.初始化as[i]=i:对as数组依照num ...
- poj 3928 树状数组
题目中只n个人,每个人有一个ID和一个技能值,一场比赛需要两个选手和一个裁判,只有当裁判的ID和技能值都在两个选手之间的时候才能进行一场比赛,现在问一共能组织多少场比赛. 由于排完序之后,先插入的一定 ...
- POJ 2299 树状数组+离散化求逆序对
给出一个序列 相邻的两个数可以进行交换 问最少交换多少次可以让他变成递增序列 每个数都是独一无二的 其实就是问冒泡往后 最多多少次 但是按普通冒泡记录次数一定会超时 冒泡记录次数的本质是每个数的逆序数 ...
- poj 2299 树状数组求逆序对数+离散化
Ultra-QuickSort Time Limit: 7000MS Memory Limit: 65536K Total Submissions: 54883 Accepted: 20184 ...
- poj 2182 树状数组
这题对于O(n^2)的算法有很多,我这随便贴一个烂的,跑了375ms. #include<iostream> #include<algorithm> using namespa ...
- POJ 2352 树状数组
学习自:链接以及百度百科 以及:https://www.bilibili.com/video/av18735440?from=search&seid=363548948825132979 理解 ...
- POJ 2299树状数组求逆序对
求逆序对最常用的方法就是树状数组了,确实,树状数组是非常优秀的一种算法.在做POJ2299时,接触到了这个算法,理解起来还是有一定难度的,那么下面我就总结一下思路: 首先:因为题目中a[i]可以到99 ...
- MooFest POJ - 1990 (树状数组)
Every year, Farmer John's N (1 <= N <= 20,000) cows attend "MooFest",a social gather ...
随机推荐
- PHP入门part1
有人说php是世界上最好的语言,那它好在哪呢. 它是开源自由的软件,能够在所有的操作平台上稳定的运行,入门比较简单.对于我这种没学过什么计算机语言的人是最好的起步点. PHP现在的含义:Hypetex ...
- DDL DML DCL语句
总体解释:DML(data manipulation language):自动提交的数据库操作语言 它们是SELECT.UPDATE.INSERT.DELETE,就象它的名字一样 DDL( ...
- 112、两个Activity切换黑屏问题
<activity android:name=".main.select.ActDoyenActivity" android:screenOrientation=" ...
- 五、selecting with the API
1. 命令通常从selection list中得到input, 调用MGlobal::getActiveSelectionList(MSelectionList &dest, bool ord ...
- php标记,变量,常量
php标记 语法:有4种书写格式 1.<?php ... ?> 强烈推荐使用. 如果当前 php的代码段,是整个文档的最后一段,可以省略结束标记?(建议省略) 每句语句都要以分号;结束. ...
- Redis的Python客户端redis-py的初步使用
1. Redis的安装 sudo pip install redis sudo pip install hiredis Parser可以控制如何解析redis响应的内容.redis-py包含两个Par ...
- spring security method security
参考 Spring Security 官方文档 http://www.concretepage.com/spring/spring-security/preauthorize-postauthoriz ...
- LeetCode344:Reverse String@Python
Write a function that takes a string as input and returns the string reversed. Example: Given s = &q ...
- Python文档
详细的为代码编写文档,这其实是写好代码的重要部分. 常见编写代码的陷阱: 1.别忘了冒号.一定要记住在复合语句首行末未输入":" 2.从第一行开始.要确定顶层(无嵌套)程序代码从第 ...
- c# 文件夾操作
#region 圖片對應異動 string newFilePath = "~/FileUpLoad/Book/" + bookModel.BookNo; ...