题目描述

Two out-of-control cars crashed within about a half-hour Wednesday afternoon on Deer Park Avenue. This accident alarmed the district government.
It jumpstarted a vibrant new technology to predict potential car accidents.
Engineers depicted a moving vehicle as a triangle with directional movement.
Three two dimeniaonal points (x1,y1),(x2,y2) and (x3,y3) restrict the span of a vehicle.
Its moverment is a uniform linear motion described by a vector (dx,dy).
That is say that after one second,the i-th endpoint of the emulational vehicle,the triangle,should be at (xi+dx,yi+dy).
The core function of this technology is simple.
For two given triangles,corresponding to two vehicles,predict that if they would collide in the near future.
Two triangles are considered collided,if they touched in some points or their intersection is not empty.
The first line of the input contains an integer tt specifying the number of test cases.
Each test case is consist of two lines and each line contains eight integers x1,y1,x2 ,y2,x3,y3 and dx,dy,to describe a vehicle and its movement.
The absolute value of each input number should be less than or equal to 10^9.
For each test case output the case number first. Then output YES if they would collide in the near future,or NO if they would never touch each other.

输入

 

输出

 

样例输入

3

0 1 2 1 1 3 1 0
9 2 10 4 8 4 -1 0 0 1 2 1 1 3 2 0
9 2 10 4 8 4 3 0 0 1 2 1 1 3 0 0
0 4 1 6 -1 6 1 -2

样例输出

Case #1: YES
Case #2: NO
Case #3: YES 题意:给你两个三角形,这两个三角形分别有x轴,y轴方向的速度,问你这两个三角形可不可能相撞(某一时刻两个三角形面积的交不为空)
思路:我们先固定一个三角形,将两个速度合成一个合速度,然后看动的那个三角形的三个定点发出的以合速度为方向的射线与定三角形的三条边有无交点
trick就是需要分别固定两个三角形.
我们将问题转化为了射线与线段相交.这个与两直线相交有什么区别呢?
1.交点应该在那个线段中间,我们用线段的两端点的坐标与交点坐标比较大小即可
2.交点应该在那个射线的一侧,我们用t来判断下射线的正方向
代码如下:
 #include <bits/stdc++.h>
using namespace std;
struct Point{double x,y;} ;//// 直线交点函数
int LineIntersect(Point A,Point B,Point C,Point D,double &x,double &y)
{
double a1,a2,b1,b2,c1,c2;
double Delta , Delta_x , Delta_y;
a1 = B.x - A.x; b1 = C.x - D.x; c1 = C.x - A.x;
a2 = B.y - A.y; b2 = C.y - D.y; c2 = C.y - A.y;
Delta=a1*b2-a2*b1; Delta_x=c1*b2-c2*b1;Delta_y=a1*c2-a2*c1;
if(Delta){
x = A.x+a1*(Delta_x/Delta);
y = A.y+a2*(Delta_x/Delta);
return ; //返回1: 表示两条直线相交,且交点是(x , y)
}
else
{
if(!Delta_x && !Delta_y) return -; //返回是-1: 表示两条直线是重合关系
else return ; //返回0:表示两条直线是平行不相交关系
}
}
bool judge (Point a[],Point b[],double dx,double dy,int i,int j)
{
Point cc;
cc.x=b[j].x+dx;cc.y=b[j].y+dy;
double xx,yy;
double maxx,maxy,minx,miny;
int ins = LineIntersect(a[i],a[(i+)%],b[j],cc,xx,yy);
maxx = max(a[i].x,a[(i+)%].x);
maxy = max(a[i].y,a[(i+)%].y);
minx = min(a[i].x,a[(i+)%].x);
miny = min(a[i].y,a[(i+)%].y);
double t = (xx-b[j].x)/dx;
if (ins==&&t>&&(minx<=xx&&xx<=maxx)&&(miny<=yy&&yy<=maxy))
return true;
else
return false;
}
Point a[],b[];
double dx1,dy1,dx2,dy2;
int main()
{
int casee = ;
int T;
scanf("%d",&T);
while (T--){
for (int i=;i<;++i) scanf("%lf%lf",&a[i].x,&a[i].y);
scanf("%lf%lf",&dx1,&dy1);
for (int i=;i<;++i) scanf("%lf%lf",&b[i].x,&b[i].y);
scanf("%lf%lf",&dx2,&dy2);
dx2-=dx1;
dy2-=dy1;
bool f = false;
for (int i=;i<;++i){
for (int j=;j<;++j){
if (judge(a,b,dx2,dy2,i,j))
f = true;
if (judge(b,a,-dx2,-dy2,i,j))
f = true;
}
}
if (f)
printf("Case #%d: YES\n",++casee);
else
printf("Case #%d: NO\n",++casee);
}
return ;
}
 

2017 ACM-ICPC乌鲁木齐网络赛 B. Out-out-control cars(计算几何 直线相交)的更多相关文章

  1. 【2017 ACM/ICPC 乌鲁木齐赛区网络赛环境测试赛 E】蒜头君的排序

    [链接]h在这里写链接 [题意] 在这里写题意 [题解] 莫队算法+树状数组. 区间增加1或减少1. 对逆序对的影响是固定的. (用冒泡排序变成升序的交换次数,就是逆序对的个数) [错的次数] 0 [ ...

  2. HDU 4731 Minimum palindrome 2013 ACM/ICPC 成都网络赛

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=4731 题解:规律题,我们可以发现当m大于等于3时,abcabcabc……这个串的回文为1,并且字典数最小 ...

  3. HDU 4734 F(x) 2013 ACM/ICPC 成都网络赛

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=4734 数位DP. 用dp[i][j][k] 表示第i位用j时f(x)=k的时候的个数,然后需要预处理下小 ...

  4. HDU 4741 Save Labman No.004 2013 ACM/ICPC 杭州网络赛

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=4741 题意:给你两条异面直线,然你求着两条直线的最短距离,并求出这条中垂线与两直线的交点. 需要注意的是 ...

  5. 2013 ACM/ICPC 成都网络赛解题报告

    第三题:HDU 4730 We Love MOE Girls 传送门:http://acm.hdu.edu.cn/showproblem.php?pid=4730 水题~~~ #include < ...

  6. 2013 ACM/ICPC 长春网络赛E题

    题意:给出一个字符串,要从头.尾和中间找出三个完全相等的子串,这些串覆盖的区间互相不能有重叠部分.头.尾的串即为整个字符串的前缀和后缀.问这个相同的子串的最大长度是多少. 分析:利用KMP算法中的ne ...

  7. 2013 ACM/ICPC 长春网络赛F题

    题意:两个人轮流说数字,第一个人可以说区间[1~k]中的一个,之后每次每人都可以说一个比前一个人所说数字大一点的数字,相邻两次数字只差在区间[1~k].谁先>=N,谁输.问最后是第一个人赢还是第 ...

  8. 2013 ACM/ICPC 长沙网络赛J题

    题意:一个数列,给出这个数列中的某些位置的数,给出所有相邻的三个数字的和,数列头和尾处给出相邻两个数字的和.有若干次询问,每次问某一位置的数字的最大值. 分析:设数列为a1-an.首先通过相邻三个数字 ...

  9. 2013 ACM/ICPC 南京网络赛F题

    题意:给出一个4×4的点阵,连接相邻点可以构成一个九宫格,每个小格边长为1.从没有边的点阵开始,两人轮流向点阵中加边,如果加入的边构成了新的边长为1的小正方形,则加边的人得分.构成几个得几分,最终完成 ...

  10. hdu 4762 && 2013 ACM/ICPC 长春网络赛解题报告

    这次的答案是猜出来的,如果做得话应该是应该是一个几何概型的数学题: 答案就是:n/(m^(n-1)); 具体的证明过程: 1.首先枚举这M个点中的的两个端点,概率是:n*(n-1); 2.假设这个蛋糕 ...

随机推荐

  1. Linux(RHEL7)下安装vsftp服务

    1.安装vsftp(没有配置yum源的先配置yum源) yum install -y vsftpd 2.启动ftp服务 systemctl start vsftpd.service 3.打开防火墙 f ...

  2. 洛谷P1982 小朋友的数字

    题目传送门 这个题的题目有点长,我们先来分析一波. 首先,这个题目中提到了以下几个量 1.最直接的就是每个小盆友手上的数字,这是题目给你的 2.每个小盆友的特征值 题目中给的定义是:每个小朋友的特征值 ...

  3. java 为啥可打印date

    打印一个对象的时候,会打印出它的toString方法的返回值,Date重写了toString方法.

  4. 【ABAP系列】SAP 后台JOB如何DEBUG

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[ABAP系列]SAP 后台JOB如何DEBUG ...

  5. Struts2之下载

    下载页面 <%@ page language="java" contentType="text/html; charset=UTF-8" pageEnco ...

  6. hdu5858 Hard problem(求两圆相交面积)

    题目传送门 Hard problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Other ...

  7. ASP.NET CORE 2.0 模板 (Admin LTE)

    原文:https://www.jianshu.com/p/4916f380be66?utm_campaign=hugo&utm_medium=reader_share&utm_cont ...

  8. NGUI的下拉框的使用(popup list script)

    一,我们先添加一个sprite,选择sprite,右键选择attach,添加box collider, 然后右键选择attach,添加popup list script ,我们给popup list ...

  9. 找回git rebase --skip消失的代码

    1.git reflog操作,查看提交的历史记录,找到自己的提交 2.强制回退到上一次提交:git reset --hard  791a1fc 或者 git reset --hard  HEAD@{2 ...

  10. 负载均衡算法WeightedRoundRobin(加权轮询)简介及算法实现

    Nginx的负载均衡默认算法是加权轮询算法,本文简单介绍算法的逻辑,并给出算法的Java实现版本. 本文参考了Nginx的负载均衡 - 加权轮询 (Weighted Round Robin).     ...