题目链接

 /*
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. slf4j和log4j结合使用步骤

    使用slf4j的优点: 提供带参数的日志输出方法(SLF4J 1.7及以后版本). pom中只需引入slf4j-log4j12,然后maven会引入它所依赖的其它JAR包. slf4j和log4j结合 ...

  2. 剑指offer 面试57题

    面试57题: 题目:和为s的数字 题目描述 输入一个递增排序的数组和一个数字S,在数组中查找两个数,是的他们的和正好是S,如果有多对数字的和等于S,输出两个数的乘积最小的.   输出描述: 对应每个测 ...

  3. 阿里云centos+java环境搭建

    目录 .准备 .安装jdk .安装tomcat .安装mysql 1.准备 购买阿里云服务器,我买的是Centos 6.5. 因为是linux,在window下管理我使用XManager,这个软件可以 ...

  4. 面向对象之继承(Day24)

    一.继承 1.什么是继承 继承是一种创建新类的方式,在Python中,新建的类可以继承一个或多个父类,父类又可称为基类或超类,新建的类称为派生类或子类 2.继承与抽象(先抽象再继承) 抽象基抽取类似或 ...

  5. [不常用] - CSRF(跨站点请求伪造)

    CSRF,Cross Site Request Forgery,即跨站点请求伪造.   这种攻击是指,在用户正常登录系统以后,攻击者诱使用户访问一些非法链接,以执行一些非法操作. 比如:如果删除用户操 ...

  6. openstack ocata版(脚本)控制节点安装

    一.初始化环境: 1.更换yum源: yum install -y wget mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS- ...

  7. 如何选择合适的Linux系统进行桌面程序开发?

    32 or 64 ? 众所周知,64位的Windows系统可以近乎完美地运行32位的应用程序,微软出于商业考虑做了这样一个兼容层.而Linux系统则划分的很清楚,默认情况下64位的Linux系统无法运 ...

  8. oracle 定时删除3天前的备份数据

    不需要保留那么多,按公司要求只需要保留一个星期的即可. 1.那么有什么方法自动删除7天以前备份的*.log文件呢? 2.服务器过多,不可能一一手动创建,有没有自动完成这个创建计划任务的批处理呢? 首先 ...

  9. Django框架之cookie和session及开发登录功能

    1.cookie是什么? Web应用程序是使用HTTP协议传输数据的.HTTP协议是无状态的协议.一旦数据交换完毕,客户端与服务器端的连接就会关闭,再次交换数据需要建立新的连接.这就意味着服务器无法从 ...

  10. 九、goroutine和channel

    进程和线程 A)进程是程序在操作系统中的一次执行过程,系统进行资源分配和调度的一个独立单元 B)线程是进程的一个执行实体,是CPU调度和分派的基本单位,它是比进程更小的能独立运行的基本单位 C)一个进 ...