POJ 2352 Stars(线段树)
题目地址: id=2352">POJ 2352
今天的周赛被虐了。
。
TAT..线段树太渣了。。得好好补补了(尽管是从昨天才開始学的。。不能算补。。。)
这题还是非常easy的。。维护信息是每个横坐标的出现的次数。
代码例如以下:
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>
#include <queue>
#include <map>
#include <set>
#include <algorithm> using namespace std;
#define lson l, mid, rt<<1
#define rson mid+1, r, rt<<1|1
struct node
{
int x, y;
} star[40000];
int cmp(node x, node y)
{
if(x.y==y.y)
{
return x.x<y.x;
}
return x.y<y.y;
}
int sum[323000], _hash[130000];
void PushUp(int rt)
{
sum[rt]=sum[rt<<1]+sum[rt<<1|1];
}
void update(int x, int l ,int r, int rt)
{
if(l==r)
{
sum[rt]++;
return ;
}
int mid=l+r>>1;
if(x<=mid) update(x,lson);
else update(x,rson);
PushUp(rt);
}
int query(int ll, int rr, int l, int r, int rt)
{
if(ll<=l&&rr>=r)
{
return sum[rt];
}
int mid=l+r>>1;
int ans=0;
if(ll<=mid) ans+=query(ll,rr,lson);
if(rr>mid) ans+=query(ll,rr,rson);
return ans;
}
int main()
{
int n, x, y, i, j, ans, max1=-1;
scanf("%d",&n);
memset(sum,0,sizeof(sum));
for(i=0; i<n; i++)
{
scanf("%d%d",&star[i].x,&star[i].y);
if(max1<star[i].x)
max1=star[i].x;
}
sort(star,star+n,cmp);
memset(_hash,0,sizeof(_hash));
for(i=0; i<n; i++)
{
ans=query(0,star[i].x,0,max1,1);
update(star[i].x,0,max1,1);
_hash[ans]++;
}
for(i=0; i<n; i++)
{
printf("%d\n",_hash[i]);
}
return 0;
}
POJ 2352 Stars(线段树)的更多相关文章
- [POJ] 2352 Stars [线段树区间求和]
Stars Description Astronomers often examine star maps where stars are represented by points on a pla ...
- POJ 2352 Stars 线段树
题目链接 题意:在一个二维平面上有n个星星,每个星星的等级为x,x为该星星左方和下方所包含的星星的数量(包含正左和正下的),输出每个等级各有多少星星,星星坐标按照y序递增给出,y值相同按照x递增给出. ...
- POJ 2352 Stars 线段树 数星星
转载自 http://www.cnblogs.com/fenshen371/archive/2013/07/25/3214927.html 题意:已知n个星星的坐标.每个星星都有一个等级,数值等于坐标 ...
- POJ 2352 Stars(树状数组)
Stars Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 30496 Accepted: 13316 Descripti ...
- hdu 1541/poj 2352:Stars(树状数组,经典题)
Stars Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submi ...
- POJ 2352 Stars(树状数组)题解
Language:Default Stars Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 52268 Accepted: 22 ...
- POJ 2352 stars (树状数组入门经典!!!)
Stars Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 54352 Accepted: 23386 Descripti ...
- POJ 2352 Stars【树状数组】
<题目链接> 题目大意: 题目给出n个点,这些点按照y坐标的升序,若y相同,则按照x的升序顺序输入,问,在这些点中,左下角的点的数量分别在0~n-1的点分别有多少个,写出它们的对应点数. ...
- poj 2352 stars 【树状数组】
题目 题意:按y递增的顺序给出n颗星星的坐标(y相等则x递增),每个星星的等级等于在它左边且在它下边(包括水平和垂直方向)的星星的数量,求出等级为0到n-1的星星分别有多少个. 因为y递增的顺序给出, ...
- poj 2352 Stars 数星星 详解
题目: poj 2352 Stars 数星星 题意:已知n个星星的坐标.每个星星都有一个等级,数值等于坐标系内纵坐标和横坐标皆不大于它的星星的个数.星星的坐标按照纵坐标从小到大的顺序给出,纵坐标相同时 ...
随机推荐
- 福建省赛-- Common Tangents(数学几何)
Problem B Common Tangents Accept: 191 Submit: 608 Time Limit: 1000 mSec Memory Limit : 32768 K ...
- hdoj--2098--分拆素数和(水题)
分拆素数和 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Subm ...
- magnify.m —— 图像局部放大镜工具函数
magnify.m 函数下载地址:magnify - File Exchange - MATLAB Central: magnify.m 函数在执行时,是一种交互式处理. 简单演示如下: clear, ...
- zookeeper的理解与概述
文章转自https://www.cnblogs.com/likehua/p/3999600.html 感谢博主 文章转自:http://www.aboutyun.com/thread-9266-1- ...
- CURRENMONTH TAG in Automation Framework
/** * @param input * <CURRENTMONTH><CURRENTMONTH+1> * @return Month "MM" */ pr ...
- 集合HashSet的使用
集合中的HashSet底层是通过Hash表实现,HashSet的特点是元素唯一,但用到Hash表就跟hashCode()有了密不可分的联系,所以HashSet的唯一性是通过hashCode()方法来保 ...
- form表单加密前台js后台java
1.前台javascript 1.在提交的js中这样写 <!-- 加密解密 --> document.form1.username.value=encode64(document.form ...
- Android控件postDelayed用法,View自带的定时器
有一个需求是这样的,点击加关注按钮后,执行关注操作,成功后按钮文字变为“已关注”,保持3秒,三秒后按钮文字便问“取消关注”,点击后执行取消关注的操作 源码: public boolean postDe ...
- ora_tool
#!/bin/ksh # # Copyright (c) 1998, 2002, Oracle Corporation. All rights reserved. # version() { ...
- Linux VNC Viewer客户端
1.realvnc-vnc-viewer 这个我感觉应该是做的做好用的VNC Viewer客户端了,毕竟是商业软件,但是VNC Viewer客户端是免费的.使用前 需要到官网下载对应发行版的软件包进行 ...