2016 微软秋招(校招)在线笔试 题目1 : Farthest Point

来源:互联网 发布:中级java程序员要求 编辑:程序博客网 时间:2024/06/01 01:33

题目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


//未优化版本import java.util.LinkedList;import java.util.Scanner;class Point{    public long x;    public long y;    public Point(long X, long Y){        this.x = X;        this.y = Y;    }}public class T1 {    public static boolean isInCircle(long x, long y, double x0, double y0, double r){        if(distance_2(x, y, x0, y0) <= r*r){            return true;        } else {            return false;        }    }    public static double distance_2(long x, long y, double x0, double y0){        double deltaX = x - x0;        double deltaY = y - y0;        return deltaX * deltaX + deltaY * deltaY;    }    public static void main(String[] args) {        Scanner input = new Scanner(System.in);        double x,y,r;        x = input.nextDouble();        y = input.nextDouble();        r = input.nextDouble();        long left = (int)(x - r), right = (int)(x + r), top = (int)(y + r), bottom = (int)(y - r);        double maxDistance = 0;        LinkedList<Point> points = new LinkedList<Point>();        for(long i = left; i <= right; i++){            if(isInCircle(i, top, x, y, r)){                double curDistance = distance_2(i, top, x, y);                if(curDistance >= maxDistance){                    maxDistance = curDistance;                    points.add(new Point(i, top));                }            }        }        for(long i = left; i <= right; i++){            if(isInCircle(i, bottom, x, y, r)){                double curDistance = distance_2(i, bottom, x, y);                if(curDistance >= maxDistance){                    maxDistance = curDistance;                    points.add(new Point(i, bottom));                }            }        }        for(long i = bottom; i <= top; i++){            if(isInCircle(left, i, x, y, r)){                double curDistance = distance_2(left, i, x, y);                if(curDistance >= maxDistance){                    maxDistance = curDistance;                    points.add(new Point(left, i));                }            }        }        for(long i = bottom; i <= top; i++){            if(isInCircle(right, i, x, y, r)){                double curDistance = distance_2(right, i, x, y);                if(curDistance >= maxDistance){                    maxDistance = curDistance;                    points.add(new Point(right, i));                }            }        }        for(Point pt : points){            if(distance_2(pt.x,pt.y, x, y) < maxDistance){                points.remove(pt);            }        }        long maxX = points.get(0).x;        LinkedList<Point> resultPts = new LinkedList<Point>();        for(Point pt : points){            if(pt.x > maxX){                maxX = pt.x;            }        }        for(Point pt : points){            if(pt.x == maxX){                resultPts.add(pt);            }        }        Point resultPt = resultPts.get(0);        for(Point pt : resultPts){            if(pt.y > resultPt.y){                resultPt = pt;            }        }        System.out.println(resultPt.x+" "+resultPt.y);    }}
0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 月经期间肚子疼的厉害怎么办 大姨吗来了肚子疼该怎么办 孕妇7个月拉肚子怎么办 胃疼肚子也疼怎么办 6个月孕妇肚子疼怎么办 孕妇4个月肚子疼怎么办 孕妇5个月拉肚子怎么办 4个月孕妇拉肚子怎么办 怀孕5个月拉肚子怎么办 肠胃老是胀气很不舒服怎么办 肚子里有气排不出来怎么办 小兔子不吃兔粮怎么办 泰迪肚子一直叫怎么办 狗狗肚子响该怎么办 狗狗肚子一直响怎么办 一刮风空调就响怎么办 胃里有气往上顶怎么办 胃里难受想吐怎么办 胃里感觉有水怎么办 喉咙总有气堵着怎么办 胃难受恶心想吐怎么办 胃里有气怎么办总放屁 肚子里有气很痛怎么办 胃有气排不出来怎么办 狗狗又吐又拉稀怎么办 狗吐了又拉稀怎么办 金毛狗又拉又吐怎么办 狗狗拉稀像水怎么办 狗狗拉稀带血怎么办 小狗狗又吐又拉怎么办 6个月婴儿拉肚子怎么办 一岁宝宝拉稀水怎么办 16个月宝宝拉稀怎么办 吃太多撑的胃疼怎么办 吃的撑的胃难受怎么办 9岁小儿肠鸣腹泻怎么办 吃凉的肠鸣腹泻怎么办 牛不排便不倒嚼怎么办 牛不吃草涨肚怎么办 牛吃玉米吃撑了怎么办 吃了块鸡骨头怎么办