• Points on Cycle


    Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

    Description

    There is a cycle with its center on the origin. 
    Now give you a point on the cycle, you are to find out the other two points on it, to maximize the sum of the distance between each other 
    you may assume that the radius of the cycle will not exceed 1000.
     

    Input

    There are T test cases, in each case there are 2 decimal number representing the coordinate of the given point.
     

    Output

    For each testcase you are supposed to output the coordinates of both of the unknow points by 3 decimal places of precision 
    Alway output the lower one first(with a smaller Y-coordinate value), if they have the same Y value output the one with a smaller X. 

    NOTE
    when output, if the absolute difference between the coordinate values X1 and X2 is smaller than 0.0005, we assume they are equal.
     

    Sample Input

    2 1.500 2.000 563.585 1.251
     

    Sample Output

    0.982 -2.299 -2.482 0.299 -280.709 -488.704 -282.876 487.453
     
     
    //题目大意是一个圆内有一点(半径未知),要求过这个点做圆内最大周长的三角形
    这道题其实不难,关键是你能不能找到公式... 就是旋转向量法(算法竞赛入门经典训练指南256页),没有书就用普通方法也行:
    一个圆的内接三角形周长最长的是正三角形。设给出的为点A(x,y),圆的半径为R,连接AO,反向延长AO与圆交于点O',以O'为圆心,R为半径画圆,两个圆的交点坐标就是所求的答案。
    这个方法就看我同学的博客吧!点击查看
    下面是我的:
    #include <iostream>
    #include<cmath>
    #include<algorithm>
    #include<cstdio>
    
    using namespace std;
    const  double PI=acos(-1.0);
    struct Point
    {
        double x;
        double y;
        Point(double x = 0, double y = 0): x(x), y(y){}
    };
    typedef Point Vector;
    Vector Rotate(Vector A, double rad)//向量旋转公式
    {
        return Vector(A.x * cos(rad) - A.y * sin(rad), A.y * cos(rad) + A.x * sin(rad));
    }
    
    int main()
    {
        Point point[3];
        int n;
        scanf("%d",&n);
        while(n--)
        {
            scanf("%lf %lf",&point[0].x,&point[0].y);
            point[1]=Rotate(point[0],PI*2/3);//逆时针旋转120度
            point[2]=Rotate(point[0],-PI*2/3);//顺时针旋转120度
            int maxPoint=(point[1].y<point[2].y || point[1].y==point[2].y && point[1].x<point[2].x)?1:2;//排序
            if(maxPoint==1)
                printf("%.3lf %.3lf %.3lf %.3lf
    ",point[1].x,point[1].y,point[2].x,point[2].y);
            if(maxPoint==2)
                printf("%.3lf %.3lf %.3lf %.3lf
    ",point[2].x,point[2].y,point[1].x,point[1].y);
        }
        return 0;
    }
    View Code
  • 相关阅读:
    qemu 系列
    vuex
    gpio led学习
    [Java] 容器-03 增强的For循环 / Set 方法
    [Java] 容器-02 HashSet 类 / Iterator 接口
    [Java] 容器-01 实现 Comparable 接口 / 重写 equals 与 hashCode (1个图 1个类 3个知识点 6个接口)
    [Java] 常用类-03 File 类 (io 包中的 File) / Enum 类
    [Java] 常用类-02 基础数据类型包装类 / Math 类
    [Java] 常用类-01 String / StringBuffer
    [Java] 数组-05 binarySearch / TestArrayCopy
  • 原文地址:https://www.cnblogs.com/gdvxfgv/p/5689469.html
Copyright © 2020-2023  润新知