zoukankan      html  css  js  c++  java
  • C语言编写程序计算圆上的点的坐标

    Problem 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

    译:

    问题描述:

    有一个以原点为中心的圆
    现在给你一个圆上的点,要求你找到圆上的另外的两个点,保证这三个点彼此之间的距离最大
    你可以假设圆的半径不超过1000
    输入:
    有T个测试数据,每个测试数据要求输入两个十进制数代表给定点的坐标
    输出
    对于每个测试用例,您应该输出两个未知点的坐标,精确到小数点后3位
    总是先输出较低的值(Y坐标值较小),如果它们的Y值与较小X值的值相同的话。
    请注意
    当输出时,如果X1和X2的绝对值小于0.0005,我们假设它们相等。
    样例输入
    2
    1.500 - 2.000
    563.585 - 1.251
    样例输出
    0.982 -2.299 -2.482 0.299
    -280.709 -488.704 -282.876 487.453

    思路:圆内接正三角形时,3个点彼此之间距离最大,可以先求角度(利用atan2可以由斜率得到角度),每次旋转120,用极坐标的方式再求直角坐标。

    #include<stdio.h>
    #include<math.h>
    #define PI 3.1415926
    int main() {
    	double x, y, r, a;
    	int n;
    	scanf("%d", &n);
    	for (int i = 0; i < n; i++) {
    		scanf("%lf%lf", &x, &y);
    		r = sqrt(x*x + y * y);	//求半径
    		a = atan2(y, x);	//求角度
    		for (int i = 0; i < 2; i++) {
    			a -= PI * 2 / 3;		//旋转120度
    			printf("%0.3lf %0.3lf", r * cos(a), r * sin(a));
    			if (i == 0)
    				printf(" ");
    		}
    		printf("
    ");
    	}
    	return 0;
    }
  • 相关阅读:
    迅为-imx6ull开发板之C语言实现LED例程
    移植5.4内核到迅为I.MX6ULL开发板
    一文搞懂定制Ubuntu文件系统-基于迅为imx6开发板
    移植Linux-5.4+内核到4412开发板
    iTOP4412开发板Linux下多核处理器相关知识
    使用迅为IMX6ULL开发板第一个汇编实验(二)
    mplayer移植-迅为IMX6Q开发板
    使用迅为IMX6ULL开发板第一个汇编实验(一)
    网易2019秋招--翻转翻转
    百度2019秋招--混战世界
  • 原文地址:https://www.cnblogs.com/F-itachi/p/9974324.html
Copyright © 2011-2022 走看看