神题。同学指教。1秒AC。。。http://blog.csdn.net/jtjy568805874/article/details/50724656

#include<cstdio>
#include<cstring>
#include<ctime>
#include<algorithm>
using namespace std; const int maxn = + ;
struct point
{
double x;
double y;
int id;
}p[ * maxn];
struct Line
{
int a;
int b;
}line[maxn];
int T, n, tot;
int flag[maxn]; bool cmp(const point&a, const point&b)
{
if (a.x == b.x) return a.y < b.y;
return a.x < b.x;
} const double eps = 1e-;
#define zero(x)(((x)>0?(x):(-x))<eps) double xmult(point p1, point p2, point p0)
{
return (p1.x - p0.x)*(p2.y - p0.y) - (p2.x - p0.x)*(p1.y - p0.y);
} int dots_inline(point p1, point p2, point p3)
{
return zero(xmult(p1, p2, p3));
} int same_side(point p1, point p2, point l1, point l2)
{
return xmult(l1, p1, l2)*xmult(l1, p2, l2)>eps;
} int dot_online_in(point p, point l1, point l2)
{
return zero(xmult(p, l1, l2)) && (l1.x - p.x)*(l2.x - p.x)<eps && (l1.y - p.y)*(l2.y - p.y)<eps;
} int intersect_in(point u1, point u2, point v1, point v2)
{
if (!dots_inline(u1, u2, v1) || !dots_inline(u1, u2, v2)) return !same_side(u1, u2, v1, v2) && !same_side(v1, v2, u1, u2);
return dot_online_in(u1, v1, v2) || dot_online_in(u2, v1, v2) || dot_online_in(v1, u1, u2) || dot_online_in(v2, u1, u2);
} int main()
{
scanf("%d", &T);
while (T--)
{
long long ans = ;
scanf("%d", &n); tot = ; memset(flag, , sizeof flag);
for (int i = ; i <= n; i++)
{
scanf("%lf%lf", &p[tot].x, &p[tot].y); p[tot].id = i; tot++;
scanf("%lf%lf", &p[tot].x, &p[tot].y); p[tot].id = i; tot++;
}
sort(p, p + tot, cmp);
for (int i = ; i < tot; i++)
{
if (!flag[p[i].id])
{
flag[p[i].id] = ;
line[p[i].id].a = i;
}
else
{
line[p[i].id].b = i;
p[i].id = -p[i].id;
}
} for (int i = ; i < tot; i++)
{
if (p[i].id>)
{
int j;
for (j = i + ; p[j].id != -p[i].id; j++)
{
if (p[j].id > )
{
if (intersect_in(p[line[p[i].id].a], p[line[p[i].id].b], p[line[p[j].id].a], p[line[p[j].id].b])) ans++;
}
} for (;; j++)
{
if (j+<tot&&p[j].x == p[j + ].x&&p[j].y == p[j + ].y)
{
if (p[j+].id>)
if (intersect_in(p[line[p[i].id].a], p[line[p[i].id].b], p[line[p[j+].id].a], p[line[p[j+].id].b])) ans++;
}
else break;
}
} }
printf("%lld\n", ans);
}
return ;
}

HUST 1376 Random intersection的更多相关文章

  1. [Linked List]Intersection of Two Linked Lists

    Total Accepted: 53721 Total Submissions: 180705 Difficulty: Easy Write a program to find the node at ...

  2. codeforces 478B Random Teams

    codeforces   478B  Random Teams  解题报告 题目链接:cm.hust.edu.cn/vjudge/contest/view.action?cid=88890#probl ...

  3. 【2019.6.2】python:json操作、函数、集合、random()等

    一.json操作: json就是一个字符串,从文件中读取json,必须是json格式.j'son串中必须是双引号,不能有单引号,单引号不能转换 1.1使用: import json #使用json先引 ...

  4. Chrome V8引擎系列随笔 (1):Math.Random()函数概览

    先让大家来看一幅图,这幅图是V8引擎4.7版本和4.9版本Math.Random()函数的值的分布图,我可以这么理解 .从下图中,也许你会认为这是个二维码?其实这幅图告诉我们一个道理,第二张图的点的分 ...

  5. Math.random()

    Math.random() 日期时间函数(需要用变量调用):var b = new Date(); //获取当前时间b.getTime() //获取时间戳b.getFullYear() //获取年份b ...

  6. .Net使用system.Security.Cryptography.RNGCryptoServiceProvider类与System.Random类生成随机数

    .Net中我们通常使用Random类生成随机数,在一些场景下,我却发现Random生成的随机数并不可靠,在下面的例子中我们通过循环随机生成10个随机数: ; i < ; i++) { Rando ...

  7. 随机数(random)

    需求 Random rd=new Random(); 需要十以内的随机数  (0---10) System.out.println((int)((rd.nextDouble()*100)/10)); ...

  8. python写红包的原理流程包含random,lambda其中的使用和见简单介绍

    Python写红包的原理流程 首先来说说要用到的知识点,第一个要说的是扩展包random,random模块一般用来生成一个随机数 今天要用到ramdom中unifrom的方法用于生成一个指定范围的随机 ...

  9. [LeetCode] Random Pick Index 随机拾取序列

    Given an array of integers with possible duplicates, randomly output the index of a given target num ...

随机推荐

  1. API CLOUD 快捷键

    常用快捷键有:Ctrl+Z:撤销Ctrl+N:创建项目或文件Ctrl+Shift+F:代码格式化(这个经常用,可以美化代码,也可以通过这个检查代码是否出错)Ctrl+/ :注释和反注释Alt+/:强制 ...

  2. Sanatorium

    Sanatorium time limit per test 1 second memory limit per test 256 megabytes input standard input out ...

  3. Facade ——为子系统的一组接口提供一致界面

    Façade模式提供了子系统一组接口的一致封装特性,如下图所示: 如图所示,OperationWrapper的实现依赖SubSystem1,2等的Operation操作.但用户调用OperationW ...

  4. Android中Canvas绘图基础详解(附源码下载) (转)

    Android中Canvas绘图基础详解(附源码下载) 原文链接  http://blog.csdn.net/iispring/article/details/49770651   AndroidCa ...

  5. [转]理解SSL(https)中的对称加密与非对称加密

    加密 解密 Tweet   密码学最早可以追溯到古希腊罗马时代,那时的加密方法很简单:替换字母. 早期的密码学 古希腊人用一种叫 Scytale 的工具加密.更快的工具是 transposition ...

  6. javascript 总结学习一

    1 , javascript字符集:javascript采用的是Unicode字符集编码.为什么要采用这个编码呢?原因很简单,16位的Unicode编码可以表示地球人的任何书面语言.这是语言 国际化的 ...

  7. PAT (Advanced Level) 1114. Family Property (25)

    简单DFS. #include<cstdio> #include<cstring> #include<cmath> #include<vector> # ...

  8. java项目中使用guava的工具包的心得

    原文:http://www.   zuidaima.com/blog/3182745969511424.htm 以前只是听过这个工具包,但是真正用的话还是在D75需求中.我要实现把前台传入的list集 ...

  9. select标签 样式 及文本有空格

    <s:select name="codeid" id="codeid" multiple="false"  list="#s ...

  10. Eclipse配置

    下载地址:http://www.eclipse.org/downloads/ tomcat plugin:http://www.eclipsetotale.com/tomcatPlugin.html# ...