HDU 5862Counting Intersections
Counting Intersections
Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 51 Accepted Submission(s): 18
The input data guarantee that no two segments share the same endpoint, no covered segments, and no segments with length 0.
The first line of each test case contains a number n(1<=n<=100000), the number of segments. Next n lines, each with for integers, x1, y1, x2, y2, means the two endpoints of a segment. The absolute value of the coordinate is no larger than 1e9.
/* ***********************************************
Author :guanjun
Created Time :2016/8/18 14:20:26
File Name :p1006.cpp
************************************************ */
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <iomanip>
#include <list>
#include <deque>
#include <stack>
#define ull unsigned long long
#define ll long long
#define mod 90001
#define INF 0x3f3f3f3f
#define maxn 100010
#define cle(a) memset(a,0,sizeof(a))
const ull inf = 1LL << ;
const double eps=1e-;
using namespace std;
priority_queue<int,vector<int>,greater<int> >pq;
struct node{
int type,x,y,y2;
}nod[maxn*];
int a[maxn*];
int Maxn;
bool cmp(node a,node b){
if(a.x==b.x)return a.type<b.type;
return a.x<b.x;
}
int c[maxn*];
int lowbit(int i){
return i&(-i);
}
void add(int i,int d){
while(i<=Maxn){
c[i]+=d;
i+=lowbit(i);
}
}
int sum(int i){
int ans=;
while(i>){
ans+=c[i];
i-=lowbit(i);
}
return ans;
}
map<int,int>mp;
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif
//freopen("out.txt","w",stdout);
int t;
scanf("%d",&t);
while(t--){
mp.clear();
int n,tot=;
int all=;
scanf("%d",&n);
for(int i=;i<=n;i++){
int x1,x2,y1,y2;
scanf("%d %d %d %d",&x1,&y1,&x2,&y2);
if(x1==x2){
if(y1>y2)swap(y1,y2);
nod[tot++]={,x1,y1,y2};
a[all++]=y1;
a[all++]=y2;
}
else{
if(x1>x2)swap(x1,x2);
nod[tot++]={,x1,y1,};
nod[tot++]={,x2+,y2,-};
a[all++]=y1;
}
}
sort(a+,a+all);
int cnt=;
for(int i=;i<=all;i++){
if(!mp[a[i]])mp[a[i]]=++cnt;
}
Maxn=cnt+;
sort(nod,nod+tot,cmp);
ll ans=;
cle(c);
for(int i=;i<tot;i++){
if(nod[i].type==){
int xpy=mp[nod[i].y];
add(xpy,nod[i].y2);
}
else{
int xpl=mp[nod[i].y];
int xpr=mp[nod[i].y2];
ans+=sum(xpr)-sum(xpl-);
}
}
printf("%lld\n",ans);
}
return ;
}
HDU 5862Counting Intersections的更多相关文章
- hdu 5862 Counting Intersections
传送门:hdu 5862 Counting Intersections 题意:对于平行于坐标轴的n条线段,求两两相交的线段对有多少个,包括十,T型 官方题解:由于数据限制,只有竖向与横向的线段才会产生 ...
- HDU 5862 Counting Intersections (树状数组)
Counting Intersections 题目链接: http://acm.split.hdu.edu.cn/showproblem.php?pid=5862 Description Given ...
- HDU 5862 Counting Intersections(离散化+树状数组)
HDU 5862 Counting Intersections(离散化+树状数组) 题目链接http://acm.split.hdu.edu.cn/showproblem.php?pid=5862 D ...
- HDU 5862 Counting Intersections 扫描线+树状数组
题目链接: http://acm.split.hdu.edu.cn/showproblem.php?pid=5862 Counting Intersections Time Limit: 12000/ ...
- Hdu 5862 Counting Intersections(有n条线段,每一条线段都是平行于x轴或者y轴,问有多少个交点+树状数组区间求和单点跟新)
传送门:Hdu 5862 Counting Intersections 题意:有n条线段,每一条线段都是平行于x轴或者y轴,问有多少个交点 分析: 基本的操作流程是:先将所有的线段按照横树坐标x按小的 ...
- HDU 5862 Counting Intersections(离散化 + 树状数组)
Counting Intersections Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/ ...
- HDU 5862 Counting Intersections (离散化+扫描线+树状数组)
题意:给你若干个平行于坐标轴的,长度大于0的线段,且任意两个线段没有公共点,不会重合覆盖.问有多少个交点. 析:题意很明确,可是并不好做,可以先把平行与x轴和y轴的分开,然后把平行y轴的按y坐标从小到 ...
- hdu 1086(计算几何入门题——计算线段交点个数)
链接:http://acm.hdu.edu.cn/showproblem.php?pid=1086 You can Solve a Geometry Problem too Time Limit: 2 ...
- HDU 1142 A Walk Through the Forest (记忆化搜索 最短路)
A Walk Through the Forest Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Jav ...
随机推荐
- 【DVWA】【SQL Injection】SQL注入 Low Medium High Impossible
1.初级篇 low.php 先看源码,取得的参数直接放到sql语句中执行 if( isset( $_REQUEST[ 'Submit' ] ) ) { // Get input $id = $_REQ ...
- cstring replace
//使用后将图纸名称存储到配置 换行符用^^替换 m_sTZMC.Replace(_T("\r\n"), _T("^^")); ini.SetValueOfKe ...
- QuickClip—界面原型设计
1.需不需要设置用户登录/注册页? QuickClip没有提供该项功能.因为本产品为单纯的移动端视频编辑软件,是一个工具类软件.而且移动端软件本就追求的是方便快捷.简单易用,本产品不需要标识使用者的身 ...
- js中=,==,===的区别
= 赋值 == 先判断类型,在判断值,可以做类型转换 === 恒等判断
- react antD moment
import moment from 'moment' console.log(moment().add(1, 'days').format('YYYY-MM-DD')) //当前时间前一天 cons ...
- 网络配置:IP+NETMASK+GATEWAY+DNS
1. IP IP地址(英语:Internet Protocol Address)是一种在Internet上的给主机编址的方式,也称为网际协议地址.常见的IP地址,分为IPv4与IPv6两大类. IP ...
- keep
简介 什么是keepalived呢?keepalived是实现高可用的一种轻量级的技术手段,主要用来防止单点故障(单点故障是指一旦某一点出现故障就会导致整个系统架构的不可用)的发生.之所以说keepa ...
- 运行/调试你的PHP代码
前言 没有任何一名程序员可以一气呵成.完美无缺的在不用调试的情况下完成一个功能或模块.调试实际分很多种情况.本篇文章我分享下自己在实际开发工作中的经验,我个人理解,调试分三种,注意我所讲的是调试并非测 ...
- js之循环语句
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Shock wave
** shock wave thickness of shock wave is order of 1e-7 m why governed by Euler Equation? P334 shock ...