题目描述

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. 点击" ./start_navicat"安装出现界面便面为乱码

    环境:ubuntu16.4 下载Navicat:navicat112_mariadb_cs_x64.tar.gz 点击" ./start_navicat"安装出现界面便面为乱码 解 ...

  2. delphi 获得时间戳 毫秒数

    function DateTimeToMilliseconds(const ADateTime: TDateTime): Int64; //获得毫秒var LTimeStamp: TTimeStamp ...

  3. User-Based Collaborative Recommender System

    Collaborative Recommender System基于User给Item的打分表,认为相似度很高的用户,会对同一个item给出相似的分数,找出K个相似度最高的用户,集合他们的打分,来推算 ...

  4. HTMLTestRunner下载生成报告

    HTMLTestRunner下载地址:http://tungwaiyip.info/software/HTMLTestRunner.html,选择HTMLTestRunner.py下载 2.打开显示这 ...

  5. [BZOJ2138]stone(Hall定理,线段树)

    Description 话说Nan在海边等人,预计还要等上M分钟.为了打发时间,他玩起了石子.Nan搬来了N堆石子,编号为1到N,每堆 包含Ai颗石子.每1分钟,Nan会在编号在\([L_i,R_i] ...

  6. jvm性能监控(2)–JVM的监控工具jstat

    Jstat是JDK自带的一个轻量级工具,主要用JVM内建的指令对java应用程序的资源和性能进行实时的监控. openjdk没有jstat,jps等命令解决办法  执行以下命令即可:yum insta ...

  7. Java的socket编程中关于bufferedWriter的发送问题

    BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())); String send ...

  8. Android应用程序开发中碰到的错误和获得的小经验

    1,Installation error: INSTALL_FAILED_INSUFFICIENT_STORAGE Description:这表示手机内存不足,对内存较小的手机经常会出现这样的问题,从 ...

  9. C# 使用Silverlight打印图片

    原文:https://www.cnblogs.com/jiajiayuan/archive/2012/04/13/2444246.html Silverlight中的打印只有一个类,那就是PrintD ...

  10. JS 函数 学习笔记

    函数是一段可以反复调用的代码块.函数还能接受输入的参数,不同的参数会返回不同的值 声明函数的 5 种方式 具名函数 (function 命令) function f(x, y){ return x + ...