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 ...
随机推荐
- SpringMVC学习系列(10) 之 异常处理
在项目中如何处理出现的异常,在每个可能出现异常的地方都写代码捕捉异常?这显然是不合理的,当项目越来越大是也是不可维护的.那么如何保证我们处理异常的代码精简且便于维护呢?这就是本篇要讲的内容—>异 ...
- android学习笔记53——自动朗读TTS
自动朗读TTS android提供了自动朗读功能--其指的是支持可以对指定文本内容进行朗读,从而发出声音: 同时android的自动朗读支持还允许把文本对应的音频录制成音频文件,方便后续播放. 这种自 ...
- jQuery入门级part.1
jquery的选择器: 基本选择器: #id 根据id的属性值来获取元素 TagName 根据标签名来获取元素 selector1,selector2 匹配列表 ...
- CodeVS 数轴染色
#include<cstdio> #include<algorithm> using namespace std; #define lson rt<<1 #defi ...
- 整理: Android HAL
这篇文章整理来自http://bbs.chinaunix.net/thread-3675980-1-1.html 在论坛中看到的Android HAL讨论,有个ID描述的比较清楚,摘录如下: temp ...
- 不同hadoop集群之间迁移hive数据
#!/bin/bash #set -x DB=$1 #获取hive表定义 ret=$(hive -e 'use ${DB};show tables;'|grep -v _es|grep -v _hb| ...
- Runloop基础知识
*:first-child { margin-top: 0 !important; } body > *:last-child { margin-bottom: 0 !important; } ...
- 【练习】数据移动---parfile导出表中指定行:
要求: ①创建存放数据的文件: ②使用默认的bad文件生成方式: ③使用truncate选项方式. 1.准备条件: [oracle@host03 ~]$ mkdir datadump [oracle@ ...
- dedecms代码研究三
上次,我们从dedecms的index.PHP文件中了解到了很多信息,也提出了一些问题: 1)加载了/include/common.inc.php,里面做了哪些工作? 2)/include/arc.p ...
- PHP时间日期
PHP常用的几个时间日期函数有:date(),mktime(),strtotime(); 一.string date ( string $format [, int $timestamp ] ) 函数 ...