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); }}
- 2016 微软秋招(校招)在线笔试 题目1 : Farthest Point
- Farthest Point(微软2016校招笔试题)
- 【hihocoder】1237 : Farthest Point ->微软2016校招在线笔试题
- 2016 微软秋招(校招)在线笔试 题目234
- [微软]题目1 : Farthest Point
- 微软苏州校招笔试题目(1月10日)Colorful Lecture Note的解法
- 微软2016校招笔试题
- 2016微软校招笔试题
- 微软2016春招笔试题1
- 2016CVTE校招在线笔试题
- 亚马逊2015校招在线笔试1
- 2016腾讯校招笔试 (部分题目)
- 【2014校招】微软笔试
- 微软2016校招4月在线笔试——第一题 Font Size
- 微软2016校招4月在线笔试——第二题 403Forbidden
- 微软2016校招笔试 第一场部分题目个人思路
- 微软2016校招笔试 第二场部分题目个人思路
- 【hihocoder】Font Size(微软2016.4校招笔试题)
- The following SDK component was not installed: extra-google-m2repository
- 剑指offer—反转链表
- NSValue
- jdbc数据库的连接
- ocp-010
- 2016 微软秋招(校招)在线笔试 题目1 : Farthest Point
- UI_UITableView界面传值(将前面的属性传值和协议传值结合起来)
- 并查集
- ocp-11
- 2016 微软秋招(校招)在线笔试 题目234
- 剑指offer—合并两个排序的链表
- 制作网页2---PHP学习拾遗
- 观影有感
- HDU 2082 母函数