2017 ACM-ICPC乌鲁木齐网络赛 B. Out-out-control cars(计算几何 直线相交)
题目描述
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(计算几何 直线相交)的更多相关文章
- 【2017 ACM/ICPC 乌鲁木齐赛区网络赛环境测试赛 E】蒜头君的排序
[链接]h在这里写链接 [题意] 在这里写题意 [题解] 莫队算法+树状数组. 区间增加1或减少1. 对逆序对的影响是固定的. (用冒泡排序变成升序的交换次数,就是逆序对的个数) [错的次数] 0 [ ...
- HDU 4731 Minimum palindrome 2013 ACM/ICPC 成都网络赛
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=4731 题解:规律题,我们可以发现当m大于等于3时,abcabcabc……这个串的回文为1,并且字典数最小 ...
- 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的时候的个数,然后需要预处理下小 ...
- HDU 4741 Save Labman No.004 2013 ACM/ICPC 杭州网络赛
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=4741 题意:给你两条异面直线,然你求着两条直线的最短距离,并求出这条中垂线与两直线的交点. 需要注意的是 ...
- 2013 ACM/ICPC 成都网络赛解题报告
第三题:HDU 4730 We Love MOE Girls 传送门:http://acm.hdu.edu.cn/showproblem.php?pid=4730 水题~~~ #include < ...
- 2013 ACM/ICPC 长春网络赛E题
题意:给出一个字符串,要从头.尾和中间找出三个完全相等的子串,这些串覆盖的区间互相不能有重叠部分.头.尾的串即为整个字符串的前缀和后缀.问这个相同的子串的最大长度是多少. 分析:利用KMP算法中的ne ...
- 2013 ACM/ICPC 长春网络赛F题
题意:两个人轮流说数字,第一个人可以说区间[1~k]中的一个,之后每次每人都可以说一个比前一个人所说数字大一点的数字,相邻两次数字只差在区间[1~k].谁先>=N,谁输.问最后是第一个人赢还是第 ...
- 2013 ACM/ICPC 长沙网络赛J题
题意:一个数列,给出这个数列中的某些位置的数,给出所有相邻的三个数字的和,数列头和尾处给出相邻两个数字的和.有若干次询问,每次问某一位置的数字的最大值. 分析:设数列为a1-an.首先通过相邻三个数字 ...
- 2013 ACM/ICPC 南京网络赛F题
题意:给出一个4×4的点阵,连接相邻点可以构成一个九宫格,每个小格边长为1.从没有边的点阵开始,两人轮流向点阵中加边,如果加入的边构成了新的边长为1的小正方形,则加边的人得分.构成几个得几分,最终完成 ...
- hdu 4762 && 2013 ACM/ICPC 长春网络赛解题报告
这次的答案是猜出来的,如果做得话应该是应该是一个几何概型的数学题: 答案就是:n/(m^(n-1)); 具体的证明过程: 1.首先枚举这M个点中的的两个端点,概率是:n*(n-1); 2.假设这个蛋糕 ...
随机推荐
- Java控制台输入字符串及字符串比较
需求描述:茵茵很喜欢研究车牌号码,从车牌号码上可以看出号码注册的早晚,据研究发现,车牌号码是按字典序发放的,现在她收集了很多车牌号码,请你设计程序帮她判断注册较早的号码.车牌号码由5个字母或数字组成. ...
- iOS应用发布打包时为什么选择release,而不是debug
一.Debug和Release版本区别? 众所周知,我们进行iOS开发,在Xcode调试程序时,分为两种方式,Debug和Release,在Target的Setting中相信大家应该看到很多选项都分为 ...
- sqlalchemy.exc.IntegrityError: (mysql.connector.errors.IntegrityError) 1062 (23000): Duplicate entry '1' for key 'PRIMARY'
排错: 看到 Duplicate entry '1' for key 'PRIMARY'是主键错误 看一看自己添加的数据id是1 再查询一下数据库中的表,发现id=1的记录已经存在了 所以在代码中让i ...
- 2017/2/27-Laravel_资源控制器命令
用于处理关于图片存储的 HTTP 请求,使用 Artisan 命令 make:controller,我们可以快速创建这样的控制器 : php artisan make:controller Photo ...
- linux crontab 执行任务(7秒执行)
创建的contab 文件中,每一行都代表一项任务,每行的每个字段代表一项设置.前五个字段是时间,第六个字段是要执行的命令 minute hour day month week co ...
- 【FICO系列】SAP FICO模块-完工入库后的差异凭证处理
公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[FICO系列]SAP FICO模块-完工入库后 ...
- 应用安全-Web安全-越权漏洞整理
login->register GetPhone->GetPasswd GetPwd->GetPassword 遍历https://xx.com/contacts/new?user_ ...
- Reinforcement Learning for Self Organization and Power Control of Two-Tier Heterogeneous Networks
R. Amiri, M. A. Almasi, J. G. Andrews and H. Mehrpouyan, "Reinforcement Learning for Self Organ ...
- android项目的目录结构讲解
参考书籍:<第一行代码Android> 一:android项目的目录结构讲解 1..gradle和.idea 这两个目录下放置的都是Android Studio自动生成的一 ...
- jsp页面注册验证问题
<script type="text/javascript"> $(function(){ // 错误消息提示 var msg = "${msg}" ...