题目描述

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. Mybatis入门之MyBatis项目案例

    一.项目案例演示 后台管理系统用户数据维护平台 所有用户数据查询 单个用户数据查询 用户数据修改(完善资料) 锁定用户账号 删除用户账号 彻底删除用户账号 二.数据库数据准备工作 数据库:mysql ...

  2. PHP继承及实现

    php学习已经有一段时间了,来对之前的知识积累做个记录. php实现单继承和多实现.单继承: 一个类只能有一个extends 抽象类 ,多实现 :一个类可以implements 多个接口 举个简单的栗 ...

  3. HTML --JS 选择框

    <html> <head> <title>选择框</title> <script language="JavaScript"& ...

  4. Codeforces 1197 E (dp+sort+二分) (Rust)

    原题链接 2300分 大意 俄罗斯套娃,每个有内容半径in和外围半径out in_i<out_i 如果 in_i >= out_j ,那么j可以放在i内 定义残留空间 = 一列嵌套的套娃 ...

  5. upc 组队赛18 STRENGTH【贪心模拟】

    STRENGTH 题目链接 题目描述 Strength gives you the confidence within yourself to overcome any fears, challeng ...

  6. C# 栈=>随时读取栈中最小值

    //原理:利用两个栈,一个记录最小值,一个记录数据. using System; using System.Collections.Generic; using System.Linq; using ...

  7. Flutter 仿滴滴出行App

    绿色出行 Flutter 仿滴滴出行App 地图:采用高德地图,仅简单完成了部分功能,基础地图,地址检索,逆地理编码. 界面:仿滴滴主界面,地图中心请求动效果,服务tabs展开效果,地址检索界面,城市 ...

  8. java 关于泛型的一些知识点

    public class Generic <T>{ private T ob; public Generic(T ob){ this.ob=ob; } public T GetOb(){ ...

  9. Linux远程软件xshell的使用

    Xshell是一个linux远程命令行软件 有免费版不用破解,安装包可以找有关人士获取 要新远程一台机,可以新建会话,输入被远程系统的参数 新建会话后,点连接开始远程 远程成功的样子

  10. F Find the AFei Numbers

    链接:https://ac.nowcoder.com/acm/contest/338/F来源:牛客网 题目描述 AFei loves numbers. He defines the natural n ...