POJ1269 Intersecting Lines 2017-04-16 19:43 50人阅读 评论(0) 收藏
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 15478 | Accepted: 6751 |
Description
are the same line), 3) intersect in a point. In this problem you will use your algebraic knowledge to create a program that determines how and where two lines intersect.
Your program will repeatedly read in four points that define two lines in the x-y plane and determine how and where the lines intersect. All numbers required by this problem will be reasonable, say between -1000 and 1000.
Input
Thus each of these input lines represents two lines on the plane: the line through (x1,y1) and (x2,y2) and the line through (x3,y3) and (x4,y4). The point (x1,y1) is always distinct from (x2,y2). Likewise with (x3,y3) and (x4,y4).
Output
If the intersection is a point then your program should output the x and y coordinates of the point, correct to two decimal places. The final line of output should read "END OF OUTPUT".
Sample Input
5
0 0 4 4 0 4 4 0
5 0 7 6 1 0 2 3
5 0 7 6 3 -6 4 -3
2 0 2 27 1 5 18 5
0 3 4 0 1 2 2 5
Sample Output
INTERSECTING LINES OUTPUT
POINT 2.00 2.00
NONE
LINE
POINT 2.00 5.00
POINT 1.07 2.20
END OF OUTPUT
Source
——————————————————————————————————————题目的意思是给出4个坐标确定两条直线,问这两条直线的关系平行or重合or相交(求焦点)
先根据斜率判关系(斜率不存在特判)再套几何模板即可
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <vector>
#include <bitset> using namespace std; #define LL long long
const int INF=0x3f3f3f3f; struct Point
{
double x,y;
};
typedef struct Point point; point f(point u1,point u2,point v1,point v2)
{
point ret=u1;
double t=((u1.x-v1.x)*(v1.y-v2.y)-(u1.y-v1.y)*(v1.x-v2.x))
/((u1.x-u2.x)*(v1.y-v2.y)-(u1.y-u2.y)*(v1.x-v2.x));
ret.x+=(u2.x-u1.x)*t;
ret.y+=(u2.y-u1.y)*t;
return ret;
} int main()
{
int T;
while(~scanf("%d",&T))
{
printf("INTERSECTING LINES OUTPUT\n");
while(T--)
{
point u1,u2,v1,v2;
scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&u1.x,&u1.y,&u2.x,&u2.y,&v1.x,&v1.y,&v2.x,&v2.y);
if(u1.x==u2.x||v1.x==v2.x)
{
if(u1.x==u2.x&&v1.x==v2.x)
{
if(u1.x==v1.x) printf("LINE\n");
else printf("NONE\n");
}
else if(u1.x==u2.x)
{
double k2=(v1.y-v2.y)/(v1.x-v2.x);
printf("POINT %.2f %.2f\n",u1.x,v2.y-k2*v2.x+k2*u1.x);
}
else
{
double k1=(u1.y-u2.y)/(u1.x-u2.x);
printf("POINT %.2f %.2f\n",v1.x,u2.y-k1*u2.x+k1*v1.x);
}
}
else
{
double k1=(u1.y-u2.y)/(u1.x-u2.x);
double k2=(v1.y-v2.y)/(v1.x-v2.x);
if(k1!=k2)
{
point ans=f(u1,u2,v1,v2);
printf("POINT %.2f %.2f\n",ans.x,ans.y);
}
else
{
double ans1=k1*v1.x+u1.y-k1*u1.x;
if(ans1==v1.y)
printf("LINE\n");
else
printf("NONE\n");
}
}
}
printf("END OF OUTPUT\n");
}
return 0;
}
POJ1269 Intersecting Lines 2017-04-16 19:43 50人阅读 评论(0) 收藏的更多相关文章
- HDU1879 继续畅通工程 2017-04-12 19:12 50人阅读 评论(0) 收藏
继续畅通工程 Time Limit : 2000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Total Submis ...
- HDU6027 Easy Summation 2017-05-07 19:02 23人阅读 评论(0) 收藏
Easy Summation Time Limit: 2000/1000 MS ...
- 总结分享十大iOS开发者最喜爱的库 分类: ios相关 app相关 2015-04-03 16:43 320人阅读 评论(0) 收藏
该10大iOS开发者最喜爱的库由"iOS辅导团队"成员Marcelo Fabri组织投票选举而得,参与者包括开发者团队,iOS辅导团队以及行业嘉宾.每个团队都要根据以下规则选出五个 ...
- Hadoop入门经典:WordCount 分类: A1_HADOOP 2014-08-20 14:43 2514人阅读 评论(0) 收藏
以下程序在hadoop1.2.1上测试成功. 本例先将源代码呈现,然后详细说明执行步骤,最后对源代码及执行过程进行分析. 一.源代码 package org.jediael.hadoopdemo.wo ...
- 滑雪 分类: POJ 2015-07-23 19:48 9人阅读 评论(0) 收藏
滑雪 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 83276 Accepted: 31159 Description Mich ...
- The Pilots Brothers' refrigerator 分类: POJ 2015-06-15 19:34 12人阅读 评论(0) 收藏
The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20304 ...
- IP Address 分类: POJ 2015-06-12 19:34 12人阅读 评论(0) 收藏
IP Address Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 19125 Accepted: 11053 Desc ...
- HDU6026 Deleting Edges 2017-05-07 19:30 38人阅读 评论(0) 收藏
Deleting Edges Time ...
- HDU6029 Happy Necklace 2017-05-07 19:11 45人阅读 评论(0) 收藏
Happy Necklace Time Limit: ...
随机推荐
- 推荐一个React 入门的教程
推荐一个React 入门的教程 react 入门实例教程 Github地址:https://github.com/ruanyf/react-demos
- 不同复制模式下,如何忽略某些binlog事件
在MySQL复制中,如果slave节点上遇到错误,比如数据不存在或者主键冲突等错误时,想要忽略这些错误,可以采用以下几种方法: 1.未启用GTID模式时 只需通过设定 SQL_SLAVE_SKIP_C ...
- ORA-12560:TNS:协议器错误的解决方法
使用SQL Plus登录数据库时,系统报ORA-12560:TNS:协议器错误.之前建了三个数据库实例,删除了一个实例.现在登录其中一个数据库报此错误. 工具/原料 Oracle11g 方法/ ...
- sdk manager 代理,解决下载速度慢的问题
原文:http://blog.csdn.net/android_panda/article/details/18598883 地址:mirrors.neusoft.edu.cn 端口:80 要勾选:F ...
- ACM-Team Tic Tac Toe
我的代码: #include <bits/stdc++.h> using namespace std; int main() { char a[3][3]; int i,j=0; for( ...
- 华为5573+联通4G上网SIM+ROS hap ac-RB962UiGS-5HacT2HnT 上网
华为5573+联通4G上网SIM+ROS hap ac-RB962UiGS-5HacT2HnT 上网 原理其实是这样的,ROS的USB口连接华为5573: 华为5573看成是一个路由器,他的外网网卡走 ...
- Redux 处理异步 Action
redux-promise-utils What redux-promise-utils 是一个基于 redux-thunk 和 redux-actions 的工具,符合 FSA 规范,方便开发者处理 ...
- 潜类别模型(Latent Class Modeling)
1.潜类别模型概述 潜在类别模型(Latent Class Model, LCM; Lazarsfeld & Henry, 1968)或潜在类别分析(Latent Class Analysis ...
- MultipartFile 转换为File
选择用缓冲区来实现这个转换即使用java 创建的临时文件 使用 MultipartFile.transferto()方法 . MultipartFile multipartFile; File fil ...
- Python 2.75升级3.6.3
https://blog.csdn.net/wwwdaan5com/article/details/78218277 Centos 7 默认yum安装python 是2.7.5, (网上看了很多升级都 ...