题目1 : Farthest Point

时间限制:5000ms
单点时限:1000ms
内存限制:256MB

描述

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
// Java版本
import java.util.Scanner;

public class Main {
/*

2
0 0
0 3

1.000 1.000 5.000

 */

    public static void main(String[] args) {
        
        Scanner scanner = new Scanner(System.in);
        double x,y,r;
        x=scanner.nextDouble();
        y=scanner.nextDouble();
        r=scanner.nextDouble();
        
        int ll=(int) (x-r);
        int lr=(int)(x+r);
        int iya,iyb;
        double max=-1;
        double tmp;
        double r2=r*r;
        double result;
        int maxx=(int) x,maxy=(int) y;
        for(int ix=ll; ix<=lr; ++ix){
            //计算对应的iy
            tmp=Math.sqrt(r2-(ix-x)*(ix-x));
            iya=(int) (tmp+y)-1;
            iyb=(int) (y-tmp)-1;
            //System.out.println(iya+"  "+ iyb);
            result =( iyb-y)*( iyb-y)+(ix-x)*(ix-x);
            if(Double.compare(Math.sqrt(result), r)<=0&&Double.compare(result, max)>=0){ //大于等于
                max=result;
                maxx=ix;
                maxy=iyb;
            }
            
            iyb++;
            result =( iyb-y)*( iyb-y)+(ix-x)*(ix-x);
            if(Double.compare(Math.sqrt(result), r)<=0&&Double.compare(result, max)>=0){ //大于等于
                max=result;
                maxx=ix;
                maxy=iyb;
            }

            iyb++;
            result =( iyb-y)*( iyb-y)+(ix-x)*(ix-x);
            if(Double.compare(Math.sqrt(result), r)<=0&&Double.compare(result, max)>=0){ //大于等于
                max=result;
                maxx=ix;
                maxy=iyb;
            }

            result =( iya-y)*( iya-y)+(ix-x)*(ix-x);
            if(Double.compare(Math.sqrt(result), r)<=0&&Double.compare(result, max)>=0){ //大于等于
                max=result;
                maxx=ix;
                maxy=iya;
            }
            iya++;
            result =( iya-y)*( iya-y)+(ix-x)*(ix-x);
            
            if(Double.compare(Math.sqrt(result), r)<=0&&Double.compare(result, max)>=0){ //大于等于
                max=result;
                maxx=ix;
                maxy=iya;
            }
            
            iya++;
            result =( iya-y)*( iya-y)+(ix-x)*(ix-x);
            if(Double.compare(Math.sqrt(result), r)<=0&& Double.compare(result, max)>=0){ //大于等于
                max=result;
                maxx=ix;
                maxy=iya;
            }
        }
        
        System.out.println(maxx+" "+maxy);
        scanner.close();
    }
    
   public static void main2(String[] args) {
        
        Scanner scanner = new Scanner(System.in);
        double x,y,r;
        x=scanner.nextDouble();
        y=scanner.nextDouble();
        r=scanner.nextDouble();
        
        int ll=(int) (x-r);
        int lr=(int)(x+r);
        int ya=(int) (y+r);
        int yb=(int) (y-r);
        double max=-1;
        double tmp;
        double result;
        double r2=r*r;
        int maxx=(int) x,maxy=(int) y;
        for(int ix=ll; ix<=lr; ++ix){
            //计算对应的iy
            
            
            for( int iy=yb; iy<=ya; ++iy){
                result =( iy-y)*( iy-y)+(ix-x)*(ix-x);
                if(Double.compare(result, r2)<=0){ //如果在里面
                    if(Double.compare(result, max)>=0){
                        max=result;
                        maxx=ix;
                        maxy=iy;
                    }
                }
            }
        }
        
        System.out.println(maxx+" "+maxy);
        scanner.close();
    }
}

 

 

 

转载于:https://www.cnblogs.com/stonehat/p/4847405.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值