poj2352树状数组】的更多相关文章

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…
树状数组解决这种偏序问题是很厉害的! /* 输入按照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…
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…
题目链接: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的个…
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…
http://poj.org/problem?id=2352 这道题的题意对于住学者应该比较难理解,但是如果弄明白他的意思的话,你就会发现这就是赤裸裸的树状数组,哎,欺负我不懂是吧,当时读题读啦好久,好啦,下面说一下他的意思吧.. 由于题目已经说明y的坐标是递增顺序,所以直接考虑x的坐标就可以啦.每次当有x输入时,都求出sum(x+1)的值(注意呦,在树状数组中,可是从1开始的,而题目中的输入是包含0的),并把result[sum(x+1)]++:再更新一下,就好啦啦啦啦. 还是要注意一点,用c…
个人NO.1 一开始题意理解有错. 一星星左下边有N颗星星,那它的等级就是N. 一开始理解必须X,Y两个坐标都小于,后来根据样例看了一下只要左下方即可,X,Y坐标都小于等于即可,但不包括星星本身. #include <iostream> #include <stdio.h> #include <string.h> using namespace std; int lowbit(int x) { return x&-x; } int c[32005]; int x…
经典问题:二维偏序.给定平面中的n个点,求每个点左下方的点的个数. 因为 所有点已经以y为第一关键字,x为第二关键字排好序,所以我们按读入顺序处理,仅仅需要计算x坐标小于<=某个点的点有多少个就行. 这就是所说的:n维偏序,一维排序,二维树状数组,三维 分治 Or 树状数组套平衡树…… <法一>树状数组. #include<cstdio> #include<algorithm> #include<iostream> using namespace 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…
题意:计划在东边的城市和西边的城市中建路,东边的点从1.....n,西边的点从1......m,求这些点连起来后有多少个交叉. PS:这个题目没有任何思路,没想到是树状数组.... 交叉出5个点 分析:3,1肯定能和1与2,3,4连线,2与2,3,4的连线相交.即x,y连线肯定和a(小于x),b(大于y)的连线,或者a(大于x),b(小于y)的连线相交.就看有几条这种连线.因此可以先排序,然后直接看当前x,y的前边比y大的数目有几个.就是逆序对数,可参考POJ2299和POJ2352 ///逆序…