POJ 2352 Stars
来源:互联网 发布:淘宝宝贝描述上传图片 编辑:程序博客网 时间:2024/06/05 05:40
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<vector>
#include<cmath>
#include<stdlib.h>
#include<iomanip>
#include<list>
#include<deque>
#include<map>
#include <stdio.h>
#include <queue>
#define maxn 1000010
#define ull unsigned long long
#define ll long long
#define reP(i,n) for(i=1;i<=n;i++)
#define rep(i,n) for(i=0;i<n;i++)
#define cle(a) memset(a,0,sizeof(a))
#define mod 90001
#define PI 3.141592657
#define INF 1<<30
const ull inf = 1LL << 61;
const double eps=1e-5;
using namespace std;
bool cmp(int a,int b){
return a>b;
}
int a[32005],c[32005];
int n;
int lowbit(int i)
{
return i&(-i);
}
void add(int i,int d)
{
while(i<=32002)
{
c[i]+=d;
i+=lowbit(i);
}
}
int sum(int i)
{
int ret=0;
while(i>0)
{
ret+=c[i];
i-=lowbit(i);
}
return ret;
}
int x,y;
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
while(cin>>n&&n)
{
cle(c),cle(a);
for(int i=1;i<=n;i++)
{
scanf("%d%d",&x,&y);
++x;
a[sum(x)]++;
add(x,1);
}
for(int i=0;i<n;i++)
printf("%d\n",a[i]);
}
return 0;
}
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
51 15 17 13 35 5
Sample Output
12110
Hint
Source
- POJ 2352 STARS
- POJ 2352 Stars
- Poj 2352 Stars
- poj 2352 Stars
- poj 2352 Stars
- poj 2352 Stars
- POJ 2352 Stars
- POJ 2352 Stars
- POJ-2352-Stars
- POJ 2352 Stars
- Poj 2352 Stars 题解
- poj 2352 stars
- POJ 2352 stars
- POJ 2352 - Stars
- POJ 2352 Stars
- POJ 2352 Stars
- poj 2352 Stars
- poj 2352 Stars
- 【转载】继承(C#)
- HDU 1166 敌兵布阵
- HOJ 1876经理的烦恼
- HDU 2097Sky数
- HDU 2046骨牌铺方格(滚动数组)
- POJ 2352 Stars
- HDU-5053 the Sum of Cube
- HDU 2041
- LeetCode145 Binary Tree Postorder Traversal(迭代实现) Java
- POJ 1195 Mobile phones(二维树状数组)
- ZOJ1091 Knight Moves
- CF 275.5 A. SwapSort
- CF 277.5 B. BerSU Ball
- HDU 2594