HDU 5862 Counting Intersections(离散化+树状数组) 题目链接http://acm.split.hdu.edu.cn/showproblem.php?pid=5862 Description Given some segments which are paralleled to the coordinate axis. You need to count the number of their intersection. The input data guarant…
Counting Intersections 题目链接: http://acm.split.hdu.edu.cn/showproblem.php?pid=5862 Description Given some segments which are paralleled to the coordinate axis. You need to count the number of their intersection. The input data guarantee that no two se…
题目链接: Counting Intersections Time Limit: 12000/6000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others) Problem Description Given some segments which are paralleled to the coordinate axis. You need to count the number of their intersection…
传送门:Hdu 5862 Counting Intersections 题意:有n条线段,每一条线段都是平行于x轴或者y轴,问有多少个交点 分析: 基本的操作流程是:先将所有的线段按照横树坐标x按小的优先排序,注意是所有的线段 :(这里是将线段都去掉只保留两个端点) 然后从左到右的顺序经行扫描,遇到横的线段,如果是左端点对应的 yi 便++ , 若是右端点对应的y1便--:  遇到竖直的线段,便统计区间[y1,y2] 的数 , 看到这了是不是有点东西了呢? 如果我是按照x排序的话,两线段若想相交…
传送门:hdu 5862 Counting Intersections 题意:对于平行于坐标轴的n条线段,求两两相交的线段对有多少个,包括十,T型 官方题解:由于数据限制,只有竖向与横向的线段才会产生交点,所以先对横向线段按x端点排序,每次加入一个线段,将其对应的y坐标位置+1,当出现一个竖向线段时,查询它的两个y端点之间的和即为交点个数. 注意点:对x坐标排序是对所有线段端点排序:因为可能出现 “  1-1  “ 这样的情况,所以对于横着的线段,需要进行首尾x坐标处理:我的方法是对于x坐标,先…
题目链接: http://acm.split.hdu.edu.cn/showproblem.php?pid=5862 Counting Intersections Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) 问题描述 Given some segments which are paralleled to the coordinate axis. You need to coun…
传送门 •参考资料 [1]:算法总结:[线段树+扫描线]&矩形覆盖求面积/周长问题(HDU 1542/HDU 1828) •题意 给你 n 个矩形,求矩形并的周长: •题解1(两次扫描线) 周长可以分成两部分计算,横线和竖线: 如何求解横线的所有并的长度呢? 和求矩阵面积并的做法一样,先将 x 离散化: 每次更新的时候,记录一下上次更新后的横线总长度: ans += [现在这次总区间被覆盖的长度和上一次总区间被覆盖的长度之差的绝对值]; 求解竖线的所有并的长度何求解横线的长度相同: 需要注意的是…
线段树扫描线矩形周长并 #include <iostream> #include <cstdio> #include <algorithm> #include <cmath> #define MAXN 22222 using namespace std; int len[MAXN<<2]; bool lbd[MAXN<<2],rbd[MAXN<<2]; int numseg[MAXN<<2]; int cnt[…
String Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others) Problem DescriptionBob has a dictionary with N words in it.Now there is a list of words in which the middle part of the word has continuous letters disappeared.…
题意:给你若干个平行于坐标轴的,长度大于0的线段,且任意两个线段没有公共点,不会重合覆盖.问有多少个交点. 析:题意很明确,可是并不好做,可以先把平行与x轴和y轴的分开,然后把平行y轴的按y坐标从小到大进行排序,然后我们可以枚举每一个平行x轴的线段, 我们可以把平行于x轴的线段当做扫描线,只不过有了一个范围,每次要高效的求出相交的线段数目,可以用一个优先队列来维护平行y轴的线段的上坐标, 如果在该平行于x轴的范围就给相应的横坐标加1,这样就很容易想到是用树状数组来维护,然后每次求出最左边和最右边…