问题 B: Out-out-control cars

题目描述

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.

输入

输出

样例输入

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

样例输出

Case #1: YES
Case #2: NO
Case #3: YES
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <bitset>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <cassert>
#include <ctime>
#define rep(i,m,n) for(i=m;i<=(int)n;i++)
#define mod 100000007
#define inf 0x3f3f3f3f
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
#define pii pair<int,int>
#define sys system("pause")
#define ls rt<<1
#define rs rt<<1|1
#define all(x) x.begin(),x.end()
using namespace std;
struct Point{double x,y;}in[100]; //// 直线交点函数
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; //返回1:    表示两条直线相交,且交点是(x , y)
}else
{if(!Delta_x && !Delta_y) return -1; //返回是-1: 表示两条直线是重合关系else return 0; //返回0:表示两条直线是平行不相交关系
}
}
bool panduan(Point a[],Point b[],double e,double f,int i,int j)
{Point c;c.x=b[j].x+e;c.y=b[j].y+f;double x,y;int fan=  LineIntersect(a[i],a[(i+1)%3],b[j],c,x,y);double miax,maax,miay,maay;if(a[i].x>a[(i+1)%3].x){maax=a[i].x;miax=a[(i+1)%3].x;}else{miax=a[i].x;maax=a[(i+1)%3].x;}if(a[i].y>a[(i+1)%3].y){maay=a[i].y;miay=a[(i+1)%3].y;}else{miay=a[i].y;maay=a[(i+1)%3].y;}double t;t=(x-b[j].x)/e;if(fan==1&&t>=0&&(x>=miax&&x<=maax)&&(y>=miay&&y<=maay))return true;return false;
}
int main()
{Point a[5],b[5];int cas=1,t,i,j;
scanf("%d",&t);
double c,d,e,f;while(t--){int fl=0;rep(i,0,2)scanf("%lf %lf",&a[i].x,&a[i].y);scanf("%lf %lf",&c,&d);rep(i,0,2)scanf("%lf %lf",&b[i].x,&b[i].y);scanf("%lf %lf",&e,&f);e=e-c;f=f-d;rep(i,0,2){rep(j,0,2){if( panduan(a,b,e,f,i,j)){fl=1;break;}if(panduan(b,a,-e,-f,i,j)){fl=1;break;}}if(fl==1)break;}if(fl)printf("Case #%d: YES\n",cas++);elseprintf("Case #%d: NO\n",cas++);}return 0;
}

转载于:https://www.cnblogs.com/qksy/p/7521883.html

2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛B: Out-out-control cars相关推荐

  1. Skiing(2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛 H)

    Problem Description In this winter holiday, Bob has a plan for skiing at the mountain resort. This s ...

  2. 计蒜客-2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛H题Skiing(拓扑序求DAG最长路)

    题意: 给定一个有向无环图,求该图的最长路. 思路: 由于是有向无环图,所以最长路肯定是一个入度为0到出度为0的路径,拓扑序在确定当前点之前能够考虑到所有到它的情况,所以最后取个最值即可. 代码: # ...

  3. 2016 ACM/ICPC亚洲区青岛站现场赛(部分题解)

    摘要 本文主要列举并求解了2016 ACM/ICPC亚洲区青岛站现场赛的部分真题,着重介绍了各个题目的解题思路,结合详细的AC代码,意在熟悉青岛赛区的出题策略,以备战2018青岛站现场赛. HDU 5 ...

  4. 计蒜客 2017 ACM-ICPC 亚洲区(西安赛区)网络赛 B coin(求乘法逆元)

    Bob has a not even coin, every time he tosses the coin, the probability that the coin's front face u ...

  5. Maximum Flow(2017 ACM-ICPC 亚洲区(西安赛区)网络赛 E)

    Problem Description Given a directed graph with nn nodes, labeled 0,1,⋯,n−1. For each <i, j> s ...

  6. 2017 ACM-ICPC 亚洲区(西安赛区)网络赛 E Maximum Flow

    原题解链接:http://blog.csdn.net/kkkkahlua/article/details/78009087 他用的最小割的来求解最大流.认为只要讨论每一个点到0和n-1那个更小哪条边就 ...

  7. 2010 ACM/ICPC Online-Contest-SCU[四川赛区网络预选赛]

    Problem A.A Simple Problem 比赛时唯一做出来的一道题. 描述: Time limit: 1 second Memory limit: 256 megabytes There' ...

  8. 2017acm乌鲁木齐赛区网络赛F题tarjan缩点

    poj1236是问把一棵树变成强联通分量,于是答案就是rudu为0的和出度为0的最大值,因为假设入度为0的多一些,先每个出度为0的连接一个入度为0的,那么还剩一些入度为0的,这时候入度为0的随意连接一 ...

  9. 2014 ACM/ICPC 北京赛区网络赛解题报告汇总

    首页 算法竞赛» 信息聚合 ONLINE JUDGE 书刊杂志 BLOG» 新闻故事» 招聘信息» 投稿须知 2014 ACM/ICPC 北京赛区网络赛解题报告汇总 九月 21st, 2014 | P ...

最新文章

  1. Go学习之-用vscode写go代码遇到的问题
  2. 调剂2002年计算机科学与技术,教育部关于做好2002年全国研究生录取工作的通知...
  3. docker入门与实践之【05-Dockfile指令】
  4. html获取qq头像代码,jQuery在线获取QQ名称和头像
  5. 用Python实现智能推荐!某音,某宝都是智能推荐的,赶紧收藏!!
  6. USACO-Section1.6 Number Triangles (动态规划)
  7. Java Web应用的代码分层最佳实践。
  8. PHP 可变函数经典用法
  9. PTA 厘米换算英尺英寸
  10. 报错问题:Invalid bound statement (not found):cn.mall.dao.BookMapper.selectAll
  11. SpringSecurity实现数据库认证
  12. PHP发送邮件SMTP发邮件,超简单引用,CtrlCV即可实现邮件反馈系统
  13. 【Unity小游戏】打字消除字母
  14. 从懵懂无知到独挡一面——那些萌新程序员的进阶之路
  15. Air Quality Index,简称AQI
  16. 删掉微信好友服务器还有吗,微信被删除的好友怎么找回来 在对方不知情的情况下找回已删除的微信好友教程...
  17. 电路的升压(boost)5-12v,降压(buck)和电荷泵
  18. php源码怎么加密一点见解
  19. PythonOCC基础使用:建模——倒角倒圆(二维+三维)
  20. MATLAB 心形曲线(大赏)

热门文章

  1. 点评----和时代专线
  2. Entity Framework Core 之简单介绍
  3. Spring Data JPA 条件查询的关键字
  4. 小甲鱼python视频第八讲(课后习题)
  5. 使用 ipmitool 实现远程管理Dell 系列服务器
  6. 实现日志管理的两种方式:aop、拦截器
  7. 关于kotlin GPUImage的使用
  8. Linux USB驱动框架分析 【转】
  9. 安卓手机文件管理器简单横向评比 - imsoft.cnblogs
  10. Portal-Basic Java Web 应用开发框架:应用篇(十三) —— REST Convention