p1254.cpp

来自「大概POJ上50道比较难的题的代码」· C++ 代码 · 共 33 行

CPP
33
字号
#include <iostream>
#include <cmath>
using namespace std;
const double PI = acos(-1.0);
int main(){
    int N;
    cin >> N;
    while(N--){
        int x1,y1,d1,x2,y2,d2;
        double k1,k2,x,y;
        cin >> x1 >> y1 >> d1 >> x2 >> y2 >> d2;
        if(d1 == 0){
            k2 = tan((90.0 - d2) / 180.0 * PI);
            x = x1;
            y = k2 * (x - x2) + y2;
            printf("%.4lf %.4lf\n",x,y);
            continue;
        }
        if(d2 == 0){
            k1 = tan((90.0 - d1) / 180.0 * PI);
            x = x2;
            y = k1 * (x - x1) + y1;
            printf("%.4lf %.4lf\n",x,y);
            continue;
        }
        k1 = tan((90.0 - d1) / 180.0 * PI);
        k2 = tan((90.0 - d2) / 180.0 * PI);
        x = (k1 * x1 - k2 * x2 - y1 + y2) / (k1 - k2);
        y = k1 * (x - x1) + y1;
        printf("%.4lf %.4lf\n",x,y);
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?