zoj 1560 Hansel and Grethel(求两条直线的交点)

来源:互联网 发布:sql去除重复字段 编辑:程序博客网 时间:2024/06/05 08:18

题目地址

题目大意:给出2个点及其各自夹角,求2条直线的交点

解题思路:数学公式推导,用tan()求斜率时要将角度转换成弧度

#include <iostream>#include <cstdio>#include <cmath>#include <cstring>#include <algorithm>#include <queue>#include <string>#include <map>#include <stack>#include <list>using namespace std;const double PI = acos(-1.0);struct Point{    double x,y;    double angle;}p1,p2;int main(){    int t;    scanf("%d",&t);    while(t--)    {        scanf("%lf%lf%lf",&p1.x,&p1.y,&p1.angle);        p1.angle = 90-p1.angle;        scanf("%lf%lf%lf",&p2.x,&p2.y,&p2.angle);        p2.angle = 90-p2.angle;        double k1 = tan(p1.angle/180*PI);        double k2 = tan(p2.angle/180*PI);        double x = (k1*p1.x-k2*p2.x+p2.y-p1.y)/(k1-k2);        double y = ((p2.x-p1.x)*k1*k2+p1.y*k2-p2.y*k1)/(k2-k1);        printf("%.4lf %.4lf\n",x,y);    }    return 0;}




0 0