zoukankan      html  css  js  c++  java
  • HDU 1700 Points on Cycle (向量旋转 + 圆内接三角形周长和面积最大的是正三角形)

    题目:传送门

    题意:在一个以原点为圆心的圆中,给你圆上的一个点,让你再选两个点, 使得这三个点构成的内接正三角形周长最大。

     

    思路:

    圆周长最大的内接三角形是正三角形:证明

    面积最大的内接三角形也是正三角形:链接

     那只要将点逆时针旋转 120度 和 顺时针旋转 120 度 得到的两个点就是答案了

    #include <bits/stdc++.h>
    #define LL long long
    #define mem(i, j) memset(i, j, sizeof(i))
    #define rep(i, j, k) for(int i = j; i <= k; i++)
    #define dep(i, j, k) for(int i = k; i >= j; i--)
    #define pb push_back
    #define make make_pair
    #define INF INT_MAX
    #define inf LLONG_MAX
    #define PI acos(-1)
    #define fir first
    #define sec second
    using namespace std;
    
    const int N = 15000;
    const double eps = 1e-8;
    const double maxL = 10.0;
    
    struct Point {
        double x, y;
        Point(double x = 0, double y = 0) : x(x), y(y) { }
    };
    
    int dcmp(double x) {
        if(fabs(x) < eps) return 0; else return x < 0 ? -1 : 1;
    }
    
    Point operator + (Point A, Point B) { return Point(A.x + B.x, A.y + B.y); }
    Point operator - (Point A, Point B) { return Point(A.x - B.x, A.y - B.y); }
    Point operator * (Point A, double p) { return Point(A.x * p, A.y * p); }
    Point operator / (Point A, double p) { return Point(A.x / p, A.y / p); }
    
    double Cross(Point A, Point B) { return A.x * B.y - A.y * B.x; }
    double Dot(Point A, Point B) { return A.x * B.x + A.y * B.y; }
    double Length(Point A) { return sqrt(Dot(A, A)); }
    
    Point Rotate(Point A, double rad) { /// 向量逆时针旋转 rad (弧度)
        return Point(A.x*cos(rad) - A.y*sin(rad), A.x*sin(rad) + A.y*cos(rad));
    }
    
    Point P, ans1, ans2;
    
    const double Angle = 2.0 * PI / 3.0;
    
    void solve() {
    
        scanf("%lf %lf", &P.x, &P.y);
        ans1 = Rotate(P, Angle);
        ans2 = Rotate(P, -Angle);
    
        if(ans1.y > ans2.y) swap(ans1, ans2);
        if(ans1.y == ans2.y && ans1.x > ans2.x) swap(ans1, ans2);
        printf("%.3f %.3f %.3f %.3f
    ", ans1.x, ans1.y, ans2.x, ans2.y);
        return ;
    
    }
    
    int main() {
    
        int _; scanf("%d", &_);
        while(_--) solve();
    
        return 0;
    }
    一步一步,永不停息
  • 相关阅读:
    HDU 6096 String (AC自动机)
    [leetcode-771-Jewels and Stones]
    [leetcode-766-Toeplitz Matrix]
    [leetcode-763-Partition Labels]
    [leetcode-762-Prime Number of Set Bits in Binary Representation]
    [leetcode-738-Monotone Increasing Digits]
    [leetcode-760-Find Anagram Mappings]
    [leetcode-744-Find Smallest Letter Greater Than Target]
    [leetcode-753-Open the Lock]
    [leetcode-748-Largest Number At Least Twice of Others]
  • 原文地址:https://www.cnblogs.com/Willems/p/12484504.html
Copyright © 2011-2022 走看看