2 条题解

  • 0
    @ 2024-9-1 13:40:56

    计算几何通用解法:

    #include <bits/stdc++.h>
    
    using u32 = unsigned;
    using i64 = long long;
    using u64 = unsigned long long;
    using i128 = __int128;
    
    constexpr double PI = acos(-1);
    
    struct Point {
    	double x, y;
    };
    
    // 绕原点顺时针旋转b(弧度制)角度
    Point rotate(Point a, double b) {
        return {a.x * cos(b) + a.y * sin(b), -a.x * sin(b) + a.y * cos(b)};
    }
    
    void solve() {
    	double a, b, c, d;
    	std::cin >> a >> b >> c >> d;
    	Point A = {a, b}, B = {c, d};
    	// 将A作为 y 坐标小的,方便我们平移到原点
    	if (b > d) {
    		std::swap(A, B);
    	}
    	double dx = A.x, dy = A.y;
    	A.x = A.y = 0;
    	B.x -= dx, B.y -= dy;
    	// 接下来让 B 点顺逆时针旋转60度
    	Point C = rotate(B, 60 * PI / 180);
    	Point D = rotate(B, -60 * PI / 180);
    	if (C.x == round(C.x) && C.y == round(C.y)) {
    		std::cout << C.x + dx << " " << C.y + dy << "\n";
    	} else if (D.x == round(D.x) && D.y == round(D.y)) {
    		std::cout << D.x + dx << " " << D.y + dy << "\n";
    	} else {
    		std::cout << -1 << "\n";
    	}
    }
    
    int main() {
    	std::ios::sync_with_stdio(false);
    	std::cin.tie(nullptr);
    	std::cout << std::fixed << std::setprecision(4);
    	int t; 
    	std::cin >> t;
    	while (t --) {
    		solve();
    	}
    
    	return 0;
    }
    

    信息

    ID
    93
    时间
    1000ms
    内存
    256MiB
    难度
    5
    标签
    递交数
    33
    已通过
    14
    上传者