题目链接

 /*
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. 交叉熵(Cross-Entropy) [转载]

    交叉熵(Cross-Entropy) 交叉熵是一个在ML领域经常会被提到的名词.在这篇文章里将对这个概念进行详细的分析. 1.什么是信息量? 假设X是一个离散型随机变量,其取值集合为X,概率分布函数为 ...

  2. Python操作——Redi

    redis是一个key-value存储系统. 和Memcached类似,它支持存储的value类型相对更多,包括string(字符串).list(列表).hash(哈希).set(集合).zset(有 ...

  3. 高阶函数,map,filter,sorted

    Map:对列表中的每个元素进行操作 >>> def f(x): ...    return x * x ... >>> map(f, [1, 2, 3, 4, 5, ...

  4. 谷歌机器学习速成课程---2深入了解机器学习(Descending into ML)

    1.线性回归 人们早就知晓,相比凉爽的天气,蟋蟀在较为炎热的天气里鸣叫更为频繁.数十年来,专业和业余昆虫学者已将每分钟的鸣叫声和温度方面的数据编入目录.Ruth 阿姨将她喜爱的蟋蟀数据库作为生日礼物送 ...

  5. PMON使用手册

    转:http://www.docin.com/p-1949877603.html

  6. Nginx配置中last和break及permanent和redirect的区别

    一.不写last和break 流程就是依次执行这些rewrite rewrite break - url重写后,直接使用当前资源,不再执行location里余下的语句,完成本次请求,地址栏url不变 ...

  7. P4309 [TJOI2013]最长上升子序列

    题目 P4309 [TJOI2013]最长上升子序列 做法 最长上升序列的求法肯定是烂大街了 水题是肯定的,确定出序列的位置然后套个树状数组就好了(强制在线的话改成线段树维护前缀最值也行) 所以说这题 ...

  8. LVS 命令使用

    LVS 命令使用 查询命令 ipvsadm -L # 查看lvs负载均衡信息ipvsadm -L -n # -n 查看IP端口ipvsadm -L -c   # 显示当前连接ipvsadm -L -- ...

  9. linux 无密码登录

    环境:Linux 脚本:Python 功能:批量IP,远程执行命令.拷贝文件 运行:./ssh_scp.py iplist.txt 脚本内容: #!/usr/bin/env python# -*- c ...

  10. Go 语言为Fibonacci函数实现Read方法

    Go语言非常灵活,只要为对象实现了相应的方法就可以把他看成实现了某个接口,类似于Durk Type, 为Fibonacci实现Read方法,就可以像读取文件一样,去读取下一个Fibonacci值. 示 ...