题目链接

 /*
Name:nyoj-1132-promise me a medal
Copyright:
Author:
Date: 2018/4/26 20:26:22
Description:
向量之间的运算,不熟悉就绕蒙逼了
用 ACM国际大学生程序设计竞赛 算法与实现的模板
有个坑: 如果第二条线段的起点是第一条线段的终点,那么不需要计算 1
1 2 1 3 1 3 1 4
输出
yes 1.0 3.0 */
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
const double pi = acos(-1.0);
inline double sqr(double x) {
return x * x;
}
const double eps = 1e-;
int cmp(double x) {
if (fabs(x) < eps) return ;
if (x > )return ;
return -;
}
//point
struct point {
double x, y;
point (){}
point (double a, double b):x(a), y(b) { }
void input() {
scanf("%lf %lf", &x, &y);
}
friend point operator - (const point &a, const point &b) {
return point(a.x-b.x, a.y-b.y);
}
friend point operator * (const double &a, const point &b) {
return point (a * b.x, a*b.y);
}
friend point operator / (const point &a, const double &b) {
return point (a.x / b, a.y /b);
}
friend bool operator == (const point &a, const point &b) {
return (cmp(a.x - b.x) == && cmp(a.y - b.y) == );
}
};
double det(const point &a, const point &b) {
return a.x * b.y - a.y * b.x;
}
//line
struct line {
point a, b;
line() { }
line(point x, point y):a(x), b(y){ }
};
line point_make_line(const point a, const point b) {
return line(a, b);
}
bool parallel(line a, line b) {
return !cmp(det(a.a - a.b, b.a - b.b));
}
bool line_make_point(line a, line b, point &res) {
if(parallel(a,b)) return false;
double s1 = det(a.a-b.a, b.b - b.a);
double s2 = det(a.b-b.a, b.b - b.a);
res = (s1 * a.b - s2 * a.a)/(s1-s2);
return true;
}
int main()
{
int t;
cin>>t;
while (t--) {
point a, b ,c ,d;
cin>>a.x>>a.y>>b.x>>b.y>>c.x>>c.y>>d.x>>d.y;
line ab(a, b), cd(c, d);
if (b == c) {//如果第二条线段的起点是第一条线段的终点,那么不需要计算
cout<<"yes ";
printf("%.1f %.1f\n",b.x, b.y) ;
continue;
}
if (parallel(ab, cd)) cout<<"no\n";
else {
cout<<"yes ";
point ans;
line_make_point(ab, cd, ans);
printf("%.1f %.1f\n",ans.x, ans.y) ;
}
}
return ;
}

nyoj-1132-promise me a medal(求线段交点)的更多相关文章

  1. 谈谈"求线段交点"的几种算法(js实现,完整版)

    "求线段交点"是一种非常基础的几何计算, 在很多游戏中都会被使用到. 下面我就现学现卖的把最近才学会的一些"求线段交点"的算法总结一下, 希望对大家有所帮助.  ...

  2. poj1408(求线段交点)

    求出所有线段的交点,然后利用叉乘求四边形面积即可. // // main.cpp // poj1408 // // Created by 陈加寿 on 15/12/31. // Copyright ( ...

  3. hdu 2857:Mirror and Light(计算几何,点关于直线的对称点,求两线段交点坐标)

    Mirror and Light Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  4. hdu 2528:Area(计算几何,求线段与直线交点 + 求多边形面积)

    Area Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  5. 【计算几何初步-线段相交】【HDU1089】线段交点

    You can Solve a Geometry Problem too Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/3 ...

  6. js判断向量叉点 并求出交点坐标

     代码如下可以直接运行,判断向量相交并求出交点坐标 <!DOCTYPE html> <html> <head> <meta http-equiv=" ...

  7. UVa 11437:Triangle Fun(计算几何综合应用,求直线交点,向量运算,求三角形面积)

    Problem ATriangle Fun Input: Standard Input Output: Standard Output In the picture below you can see ...

  8. POJ_1269_Intersecting Lines_求直线交点

    POJ_1269_Intersecting Lines_求直线交点 Description We all know that a pair of distinct points on a plane ...

  9. sgu 129 Inheritance 凸包,线段交点,计算几何 难度:2

    129. Inheritance time limit per test: 0.25 sec. memory limit per test: 4096 KB The old King decided ...

随机推荐

  1. 20170330 ABAP代理生成

    在线文档ABAP代理生成, ABAP 代理生成(事物SPROXY)使您能够通过使用企业服务资源中企业服务资源库中 的接口描述在SAP系统中生成ABAP代理对象. ABAP代理生成概览: 1.代理标识, ...

  2. 如何删除github中的仓库?

    使用Github管理项目确实有些好处,但删除仓库(repositories)确实不太好找到. 首先进入要删除的仓库,点击右下角的“settings” 然后拉到页面最下面在danger zone 按“d ...

  3. 剑指offer 面试7题

    面试7题: 题目:输入某二叉树的前序遍历和中序遍历的结果,请重建出该二叉树.假设输入的前序遍历和中序遍历的结果中都不含重复的数字.例如输入前序遍历序列{1,2,4,7,3,5,6,8}和中序遍历序列{ ...

  4. Python之函数2 嵌套,作用域和闭包(Day12)

    一.函数对象 1.函数是第一类对象,即函数可以当做数据传递 1.1 可以被引用 1.2 可以当做参数传递 1.3 返回值可以是函数 1.4 可以当做容器类型的元素 二.函数的嵌套 1.函数嵌套的调用: ...

  5. 2015.7.16(小高开忍住没有减仓,大盘涨3.5%,百股涨停——买进中重、中航,指导WXL错误)

    1.大智慧轻微高开,按照昨天总结的震荡行情指导操作(pic1) a.震荡行情,开盘5分钟的走势不能指导操作, b.操作一定要等到2峰2谷出现后再做!开盘价不能作为峰.谷! c.只有当通道出现2.0%以 ...

  6. volume不能挂载mysql permission denied问题

    参考 把玩jenkins docker镜像遇到的volume权限问题 docker run -d -v /root/jenkins:/var/jenkins_home -u 0 -P --name j ...

  7. css系列(4)简介

        本节用来简单介绍css.     (1)css: CSS 指层叠样式表 (Cascading Style Sheets): 功能以及作用:1.样式定义如何显示 HTML 元素; 2.样式通常存 ...

  8. 配置NFS作为HDFS高可用的共享存储系统

    所有命令或步骤: 首先,在各个节点上安装nfs服务 yum install -y nfs service rpcbind start service nfs start 配置开机自启动服务 chkco ...

  9. 什么是JavaBeans?

    参看维基百科,归纳出以下几条: JavaBeans是指符合某些标准的类, Bean这个名称用于涵盖这个标准, 其目的在于创建可重用的Java组件. 由于Bean是很“死板”的东西,因此它可以持久存储, ...

  10. jQuery图片下滑切换焦点图

    在线演示 本地下载