题目链接

 /*
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. Django_Form表单补充

    Form表单 问题1:  注册页面输入为空,报错:keyError:找不到password def clean(self): print("---",self.cleaned_da ...

  2. or and 运算符与 pyhton编码

    运算符 # x or y 如果 x 为真,则值为x,否则为y 1 print(4 or 3) # 4 2 print(2 or 3) # 2 3 print(1 or 3) # 1 4 print(0 ...

  3. linux中安装软件的集中方法

    一.rpm包安装方式步骤: 引用:1.找到相应的软件包,比如soft.version.rpm,下载到本机某个目录:2.打开一个终端,su -成root用户:3.cd soft.version.rpm所 ...

  4. 【HackerRank】Find the Median(Partition找到数组中位数)

    In the Quicksort challenges, you sorted an entire array. Sometimes, you just need specific informati ...

  5. no xxx find in java.library.path

    JAVA系统运行时候load native lib时候会遇到下面错误,如 java.lang.UnsatisfiedLinkError: no JSTAF in java.library.path这可 ...

  6. samtools的基本用法

    1.sam,bam的格式转换: $samtools view -sb file.sam >file.bam $samtools view -sb file.sam -o file.bam #sa ...

  7. Cocos2d-x项目移植到WP8系列之五:播放MP3

    原文链接: http://www.cnblogs.com/zouzf/p/3972549.html 这一块的细节还是不太了解,只是东凑西拼能跑起来而已 1.网上下载lamb库 生成需要的lib库,详情 ...

  8. ANSI C和POSIX

    简单的说 ANSI C:标准C API(对应fopen) POSIX:方便在Linux下运行的C API(对应open)

  9. Python 字典Dict概念和操作

    # 字典概念:无序的, 可变的键值对集合 # 定义 # 方式1 # {key: value, key: value...} # 例如 # {"name": "xin&qu ...

  10. 16个tomcat面试题

    1)解释什么是Jasper? Jasper是Tomcat的JSP引擎 它解析JSP文件,将它们编译成JAVA代码作为servlet 在运行时,Jasper允许自动检测JSP文件的更改并重新编译它们 2 ...