【POJ2352】【树状数组】Stars】的更多相关文章

Astronomers often examine star maps where stars are represented by points on a plane and each star has Cartesian coordinates. Let the level of a star be an amount of the stars that are not higher and not to the right of the given star. Astronomers wa…
Description Astronomers often examine star maps where stars are represented by points on a plane and each star has Cartesian coordinates. Let the level of a star be an amount of the stars that are not higher and not to the right of the given star. As…
树状数组解决这种偏序问题是很厉害的! /* 输入按照y递增,对于第i颗星星,它的level就是之前出现过的星星中,横坐标小于i的总数 */ #include<iostream> #include<cstring> #include<cstdio> #include<algorithm> using namespace std; #define maxn 32200 int bit[maxn],n; void add(int i){ while(i<=m…
题目http://acm.hdu.edu.cn/showproblem.php?pid=1541 n个星星的坐标,问在某个点左边(横坐标和纵坐标不大于该点)的点的个数有多少个,输出n行,每行有一个数字,代表左下角个点数为i( i 从0开始)的点的个数. 首先将横坐标排序,这样就值需要比较纵坐标,可以采用hash的方法记录纵坐标为 i 的个数,每枚举到一个点hash加一,然后树状数组求纵坐标 不大于该点的 个数.值得注意的是树状数组是由 1 开始的,而题目可以从0开始,会超时,加一就好. 具体看代…
Stars Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 39186 Accepted: 17027 Description Astronomers often examine star maps where stars are represented by points on a plane and each star has Cartesian coordinates. Let the level of a star b…
Astronomers often examine star maps where stars are represented by points on a plane and each star has Cartesian coordinates. Let the level of a star be an amount of the stars that are not higher and not to the right of the given star. Astronomers wa…
经典问题:二维偏序.给定平面中的n个点,求每个点左下方的点的个数. 因为 所有点已经以y为第一关键字,x为第二关键字排好序,所以我们按读入顺序处理,仅仅需要计算x坐标小于<=某个点的点有多少个就行. 这就是所说的:n维偏序,一维排序,二维树状数组,三维 分治 Or 树状数组套平衡树…… <法一>树状数组. #include<cstdio> #include<algorithm> #include<iostream> using namespace st…
Stars Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 30496   Accepted: 13316 Description Astronomers often examine star maps where stars are represented by points on a plane and each star has Cartesian coordinates. Let the level of a st…
Stars Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 4052    Accepted Submission(s): 1592 Problem Description Astronomers often examine star maps where stars are represented by points on a plan…
Stars Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 37323 Accepted: 16278 Description Astronomers often examine star maps where stars are represented by points on a plane and each star has Cartesian coordinates. Let the level of a star b…
Stars Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/65536 K (Java/Others) Total Submission(s): 111 Accepted Submission(s): 54   Problem Description Yifenfei is a romantic guy and he likes to count the stars in the sky.To make the problem…
http://acm.hdu.edu.cn/showproblem.php?pid=1541 Stars Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 5993    Accepted Submission(s): 2384 Problem Description Astronomers often examine star maps…
Language:Default Stars Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 52268 Accepted: 22486 Description Astronomers often examine star maps where stars are represented by points on a plane and each star has Cartesian coordinates. Let the…
Stars Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 54352   Accepted: 23386 Description Astronomers often examine star maps where stars are represented by points on a plane and each star has Cartesian coordinates. Let the level of a st…
Astronomers often examine star maps where stars are represented by points on a plane and each star has Cartesian coordinates. Let the level of a star be an amount of the stars that are not higher and not to the right of the given star. Astronomers wa…
算法学习:http://www.cnblogs.com/George1994/p/7710886.html 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1541 Astronomers often examine star maps where stars are represented by points on a plane and each star has Cartesian coordinates. Let the level of a…
Astronomers often examine star maps where stars are represented by points on a plane and each star has Cartesian coordinates. Let the level of a star be an amount of the stars that are not higher and not to the right of the given star. Astronomers wa…
题目链接:https://cn.vjudge.net/problem/HDU-1541 题意 天上有许多星星 现给天空一个平面坐标轴,统计每个星星的level, level是指某一颗星星的左下角(x<=x0 && y<=y0)的星星总数 注意数据以yx排序输入 思路 怎么想也想不到如何查询 若用传统O(n^3)查询必然超时 于是想到记忆化搜索不断读写dp[y][x]即可,目测O(n^2)大一点 算了一下时间空间都不大可行,苦思冥想没有思路,看了别人的题解才晃然大雾 用树状数组维…
题目链接:https://vjudge.net/problem/POJ-2352 题意:在直角坐标系中给出n个点的 (x,y),(0<=x,y<=32000),定义每个点的level为(x',y')的数量,其中x'<=x,y'<=y.输出所有level的点的个数. 思路:这几天开始写树状数组的题,加油!!因为输入为按y升序排列,在y相等时按x升序排列.所以当输入点i时,对其level有贡献的点一定在点i之前,而不会在其后.所以点i的level为之前出现的点的横坐标<=xi的个…
一.Ultra-QuickSort(树状数组求逆序数) 题目链接(点击) Ultra-QuickSort Time Limit: 7000MS   Memory Limit: 65536K Total Submissions: 73943   Accepted: 27692 Description In this problem, you have to analyze a particular sorting algorithm. The algorithm processes a seque…
数 星 星 S t a r s 数星星 Stars 数星星Stars 题目描述 天空中有一些星星,这些星星都在不同的位置,每个星星有个坐标.如果一个星星的左下方(包含正左和正下)有 k k k 颗星星,就说这颗星星是 k k k级的. 给定星星的位置,输出各级星星的数目. 一句话题意:给定 n n n个点,定义每个点的等级是在该点左下方(含正左.正下)的点的数目,试统计每个等级有多少个点. 输入 第一行一个整数 N N N,表示星星的数目: 接下来 N N N行给出每颗星星的坐标,坐标用两个整数…
http://poj.org/problem?id=2352 这道题的题意对于住学者应该比较难理解,但是如果弄明白他的意思的话,你就会发现这就是赤裸裸的树状数组,哎,欺负我不懂是吧,当时读题读啦好久,好啦,下面说一下他的意思吧.. 由于题目已经说明y的坐标是递增顺序,所以直接考虑x的坐标就可以啦.每次当有x输入时,都求出sum(x+1)的值(注意呦,在树状数组中,可是从1开始的,而题目中的输入是包含0的),并把result[sum(x+1)]++:再更新一下,就好啦啦啦啦. 还是要注意一点,用c…
题意:求坐标0到x间的点的个数 思路:树状数组,主要是转化,根据题意的输入顺序,保证了等级的升序,可以直接求出和即当前等级的点的个数,然后在把这个点加入即可. 注意:树状数组下标从1开始(下标为0的话会出错),所以把所有的x加1存储. #include<iostream> #include<stdio.h> #include<string.h> using namespace std; #define MAXN 32005 #define MAXL 15005 int…
绝对大坑.千万记住树状数组0好下标位置是虚拟节点.详见大白书P195.其实肉眼看也能得出,在add(有的也叫update)的点修改操作中如果传入0就会死循环.最后TLE.所以下标+1解决问题.上代码! #include <iostream> #include <cstring> #include <cstdlib> #include <cstdio> #include <algorithm> #include <numeric> #i…
题目链接 给n个操作, 第一种是在x, y, z这个点+1. 第二种询问(x1, y1, z1). (x2, y2, z2)之间的总值. 用一次cdq分治可以将三维变两维, 两次的话就变成一维了, 然后最后一维用树状数组维护. 对于每个询问, 相当于将它拆成8个点. 注意第二次cdq分治的时候l可能小于r. 所以这里的return条件是l <= r而不是l == r. 找了好久... #include <bits/stdc++.h> using namespace std; #defin…
一開始想,总感觉是DP,但是最后什么都没想到.还暴力的交了一发. 然后開始写线段树,结果超时.感觉自己线段树的写法有问题.改天再写.先把树状数组的写法贴出来吧. ~~~~~~~~~~~~~~~~~~~~~~~~ 树状数组不懂的去看刘汝佳的大白书,那个图画得非常清楚. 题目大意:星星的坐标以y递增的顺序给出,这些点的左下方的点数代表这个点的级数,问0~N-1的级数有多少个?事实上y根本木实用. 题目链接:http://poj.org/problem?id=2352 http://acm.hdu.e…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1541 题目大意就是统计其左上位置的星星的个数 由于y已经按升序排列,因此只用按照x坐标生成一维树状数组即可 比较简单的题目: 代码: #include<iostream> #include<cstring> #include<cstdio> #include<cstdlib> #include<algorithm> using namespace s…
/** * @author johnsondu * @time 2015-8-22 * @type Binary Index Tree * ignore the coordinate of y and * process as 1D conditions. * @url http://poj.org/problem?id=2352 */ #include <iostream> #include <cstdio> #include <cmath> #include <…
树状数组 树状数组(Binary Indexed Tree(B.I.T), Fenwick Tree)是一个查询和修改复杂度都为log(n)的数据结构.主要用于查询任意两位之间的所有元素之和,但是每次只能修改一个元素的值:经过简单修改可以在log(n)的复杂度下进行范围修改,但是这时只能查询其中一个元素的值(如果加入多个辅助数组则可以实现区间修改与区间查询). 树状数组和线段树很像,但能用树状数组解决的问题,基本上都能用线段树解决,而线段树能解决的树状数组不一定能解决.相比较而言,树状数组效率要…
<题目链接> 题目大意: 题目给出n个点,这些点按照y坐标的升序,若y相同,则按照x的升序顺序输入,问,在这些点中,左下角的点的数量分别在0~n-1的点分别有多少个,写出它们的对应点数.  解题分析: 因为所有点是按照y坐标的升序优先给出,所以后面的点y坐标一定大于等于前面的.于是,判断该点前面有多少点满足在该点的“左下角”,只需看前面的点有几个x坐标小于当前点即可,所以,我们只需要对x坐标建一维树状数组即可求解. #include <cstdio> #include <cs…