题目描述

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. js 数组相减 (一个数组去掉不符合条件的子数组)

    数组相减?我也希望将来在ES8或者更好js版本能带来数组之间相互运算的方法,但是现在不能,咱们只能靠已有的方法实现: var arr1 = [2,3,5,88,99,444,66],arr2 = [2 ...

  2. 设置chrome解决跨域问题

    开发中遇到跨域问题, 解决方法一 以关闭安全验证模式启动chrome,就不会报跨域了  开发阶段,用这个方式是可以的,不然他需要后台配置成 * , 发布会有风险  设置方法:  --disable-w ...

  3. pojPseudoprime numbers (快速幂)

    Description Fermat's theorem states that for any prime number p and for any integer a > 1, ap = a ...

  4. 排序算法四:快速排序(Quicksort)

    快速排序(Quicksort),因其排序之快而得名,虽然Ta的平均时间复杂度也是O(nlgn),但是从后续仿真结果看,TA要比归并排序和堆排序都要快. 快速排序也用到了分治思想. (一)算法实现 pr ...

  5. python字典、字符串(json串)、字节串之间的转化

    字典和json字符串(本质也是字符串)之间的转化用json.dumps和json.loads() json.dumps():   字典→json字符串 json.loads():     json字符 ...

  6. Netty核心组件介绍及手写简易版Tomcat

    Netty是什么: 异步事件驱动框架,用于快速开发高i性能服务端和客户端 封装了JDK底层BIO和NIO模型,提供高度可用的API 自带编码解码器解决拆包粘包问题,用户只用关心业务逻辑 精心设计的Re ...

  7. 《剑指offer》面试题11 数值的整数次方 Java版

    书中方法:这道题要注意底数为0的情况.double类型的相等判断.乘方的递归算法. public double power(double base, int exponent){ //指数为0 if( ...

  8. 21、numpy—Matplotlib

    NumPy Matplotlib Matplotlib 是 Python 的绘图库. 它可与 NumPy 一起使用,提供了一种有效的 MatLab 开源替代方案. 它也可以和图形工具包一起使用,如 P ...

  9. CVE-2013-2094 porting to x86-32 分析

    /* * linux 2.6.37-3.8.8 - x86 * @rikiji * * requires System.map and /dev/ptmx * this: http://zmbs.ne ...

  10. poj2385 Apple Catching (线性dp)

    题目传送门 Apple Catching Apple Catching Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 154 ...