神题。同学指教。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. Windsock套接字I/O模型学习 --- 第一章

    1. I/O模型共有以下几种: 阻塞(blocking)模型 选择(select)模型 WSAAsyncSelect模型 WSAEventSelect模型 重叠(overlapped)模型 完成端口( ...

  2. LightOJ 1259 Goldbach`s Conjecture 素数打表

    题目大意:求讲一个整数n分解为两个素数的方案数. 题目思路:素数打表,后遍历 1-n/2,寻找方案数,需要注意的是:C/C++中 bool类型占用一个字节,int类型占用4个字节,在素数打表中采用bo ...

  3. php des 加密类

    <?php/** *@see Yii CSecurityManager; */class Des{ public static function encrypt($data,$key){ $mo ...

  4. SCRIPT7002: XMLHttpRequest: 网络错误 0x2ef3, 由于出现错误 00002ef3&nbsp

    项目使用的是tomcat7 ,浏览器是ie11 突然打开浏览器发现不能获取数据了 tomcat conf server.xml 文件 <Connector port="8080&quo ...

  5. 学习笔记——抽象工厂模式Abstract Factory

    在工厂模式的基础上,通过为工厂类增加接口,实现其他产品的生产,而不用一类产品就增加一个工厂. 依然以<真菌世界>游戏故事类比,树作为工厂,如果现在有两类树,一类生产快速弄真菌飞机和20毫米 ...

  6. Git学习 -- 管理修改

    git关注的是修改,而不是文件 commit只会提交add到暂存区的修改 撤销修改 已修改但没有add到暂存区 git checkout -- <file>     #撤销工作区中的修改 ...

  7. 转:透析QTP自动化测试框架SAFFRON

    1.为什么要使用框架? 框架是一组自动化测试的规范.测试脚本的基础代码,以及测试思想.惯例的集合.可用于减少冗余代码.提高代码生产率.提高代码重用性和可维护性.例如QTestWare就是QTP自动化测 ...

  8. Json解析要点

    解析Json时,昨天遇到了新的问题,之前都是解析的数组,不是数组的用类来做. 这是Json串; {"status":"00001","ver" ...

  9. zepto为什么不支持animate,报animate is not a function

    在zepto.min.js文件中搜索animate看有没有,如果没有就是没有加入animate的模块 解决办法,去github中打开src/文件夹,找到fx.js文件,把内容追加到zepto.min. ...

  10. li里元素都浮动 li 在IE6 7 下方会产生4px间隙问题

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...