hiho一下 第111周 AFarthest Point(计算几何)

来源:互联网 发布:项目中多线程编程案例 编辑:程序博客网 时间:2024/06/06 00:58

传送门

描述
Given a circle on a two-dimentional plane.

Output the integral point in or on the boundary of the circle which has the largest distance from the center.

输入
One line with three floats which are all accurate to three decimal places, indicating the coordinates of the center x, y and the radius r.

For 80% of the data: |x|,|y|<=1000, 1<=r<=1000

For 100% of the data: |x|,|y|<=100000, 1<=r<=100000

输出
One line with two integers separated by one space, indicating the answer.

If there are multiple answers, print the one with the largest x-coordinate.

If there are still multiple answers, print the one with the largest y-coordinate.

样例输入

1.000 1.000 5.000

样例输出

6 1

题目大意:

给定平面直角坐标系中的一个圆,求圆内(可以在边界上)离圆心最远的整点,但是如果有多组答

案的话,应该输出 x 坐标比较大的那一个,如果 x 坐标相同的话输出 y 坐标比较大的。

解题思路:

(采用hiho的答案)传送门

需要注意的是这个图 有点不太准确,他的那个 x 坐标和 y 坐标放错位置了。。。在纸上一画就知道

/**2016 - 08 - 20 上午Author: ITAKMotto:今日的我要超越昨日的我,明日的我要胜过今日的我,以创作出更好的代码为目标,不断地超越自己。**/#include <iostream>#include <cstdio>#include <cstring>#include <cstdlib>#include <cmath>#include <vector>#include <queue>#include <algorithm>#include <set>using namespace std;typedef long long LL;typedef unsigned long long ULL;const int INF = 1e9+5;const int MAXN = 1e6+5;const int MOD = 1e9+7;const double eps = 1e-9;const double PI = acos(-1);using namespace std;LL Scan_LL()///输入外挂{    LL res=0,ch,flag=0;    if((ch=getchar())=='-')        flag=1;    else if(ch>='0'&&ch<='9')        res=ch-'0';    while((ch=getchar())>='0'&&ch<='9')        res=res*10+ch-'0';    return flag?-res:res;}int Scan_Int()///输入外挂{    int res=0,ch,flag=0;    if((ch=getchar())=='-')        flag=1;    else if(ch>='0'&&ch<='9')        res=ch-'0';    while((ch=getchar())>='0'&&ch<='9')        res=res*10+ch-'0';    return flag?-res:res;}void Out(LL a)///输出外挂{    if(a>9)        Out(a/10);    putchar(a%10+'0');}double Dis(double ax, double ay, double bx, double by){    return (ax-bx)*(ax-bx)+(ay-by)*(ay-by);}int main(){    double xc, yc, r;    while(~scanf("%lf%lf%lf",&xc,&yc,&r))    {        int ret_x, ret_y;        double Max = -12345;        for(int x=floor(xc+r); x>=ceil(xc-r); x--)        {            double d = sqrt( (r*r) - (x-xc)*(x-xc) );            int ty1 = floor(yc+d), ty2 = ceil(yc-d);            if(Dis(x, ty1, xc, yc) > Max + eps)            {                Max = Dis(x, ty1, xc, yc);                ret_x = x;                ret_y = ty1;            }            if(Dis(x, ty2, xc, yc) > Max + eps)            {                Max = Dis(x, ty2, xc, yc);                ret_x = x;                ret_y = ty2;            }        }        printf("%d %d\n",ret_x, ret_y);    }    return 0;}   
0 0