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个星星的坐标.每个星星都有一个等级,数值等于坐标系内纵坐标和横坐标皆不大于它的星星的个数.星星的坐标按照纵坐标从小到大的顺序给出,纵坐标相同时 ...
随机推荐
- cpc,tank
先保存一段错误的代码 #include<iostream> #include<cstdio> #include<cstring> #include<algor ...
- poj_3468,线段树成段更新
参考自http://www.notonlysuccess.com/index.php/segment-tree-complete/ #include<iostream> #include& ...
- 38.angular的scope作用域
转自:https://www.cnblogs.com/best/tag/Angular/ 1. Scope(作用域) 是应用在 HTML (视图) 和 JavaScript (控制器)之间的纽带. S ...
- 最标准的 Java MySQL 连接
package com.runoob.test; import java.sql.*; public class MySQLDemo { // JDBC 驱动名及数据库 URL static fina ...
- UVa 11025 The broken pedometer【枚举子集】
题意:给出一个矩阵,这个矩阵由n个数的二进制表示,p表示用p位二进制来表示的一个数 问最少用多少列就能将这n个数区分开 枚举子集,然后统计每一种子集用了多少列,维护一个最小值 b[i]==1代表的是选 ...
- Linux-TCP/IP, IPv4地址类别摘要
TCP/IP分层: application layer transport layer internet ...
- 图像处理是用的数据类型uint8,double
将原图像的灰度值转换成double的作用主要是考虑计算过程中的精度的问题,double 的数据是有小数点的,而uint8是0-255的整数,如果直接用uint8计算,会在计算过程中产生舍入误差,这种误 ...
- Vue总结(二)
原始引用:开发时使用开发版本,线上使用生产版本. 原始引用到html中,在浏览器中控制台输入Vue,输出一个函数就可以. defineProperties实现的数据绑定. //defineProper ...
- NodeJS学习笔记 (28)流操作-stream(ok)
模块概览 nodejs的核心模块,基本上都是stream的的实例,比如process.stdout.http.clientRequest. 对于大部分的nodejs开发者来说,平常并不会直接用到str ...
- java uploadify 上传组件使用方法
!!!声明 1-3 是jsp页面所写内容 文中需要的util 参见百度云 http://pan.baidu.com/s/1kV0gqBt 如已失效 请加QQ1940978083 1.首先引入 ...