时间限制: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();
}
}
 

题目1 : Farthest Point的更多相关文章

  1. array题目合集

    414. Third Maximum Number 给一个非空的整数数组,找到这个数组中第三大的值,如果不存在,那么返回最大的值.要求时间复杂度为o(n) 例如: Example 1: Input: ...

  2. hihocoder 1237 Farthest Point

    #1237 : Farthest Point 时间限制:5000ms 单点时限:1000ms 内存限制:256MB 描述 Given a circle on a two-dimentional pla ...

  3. Farthest Nodes in a Tree ---LightOj1094(树的直径)

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1094 Given a tree (a connected graph with no ...

  4. LeetCode题目解答

    LeetCode题目解答——Easy部分 Posted on 2014 年 11 月 3 日 by 四火 [Updated on 9/22/2017] 如今回头看来,里面很多做法都不是最佳的,有的从复 ...

  5. Farthest Nodes in a Tree (求树的直径)

    题目链接,密码:hpu Description Given a tree (a connected graph with no cycles), you have to find the farthe ...

  6. LightOJ1094 - Farthest Nodes in a Tree(树的直径)

    http://lightoj.com/volume_showproblem.php?problem=1094 Given a tree (a connected graph with no cycle ...

  7. leetcode tree相关题目总结

    leetcode tree相关题目小结 所使用的方法不外乎递归,DFS,BFS. 1. 题100 Same Tree Given two binary trees, write a function ...

  8. E - Farthest Nodes in a Tree

    Given a tree (a connected graph with no cycles), you have to find the farthest nodes in the tree. Th ...

  9. 谈谈一些有趣的CSS题目(十二)-- 你该知道的字体 font-family

    开本系列,谈谈一些有趣的 CSS 题目,题目类型天马行空,想到什么说什么,不仅为了拓宽一下解决问题的思路,更涉及一些容易忽视的 CSS 细节. 解题不考虑兼容性,题目天马行空,想到什么说什么,如果解题 ...

随机推荐

  1. [BZOJ4568][SCOI2016]幸运数字(倍增LCA,点分治+线性基)

    4568: [Scoi2016]幸运数字 Time Limit: 60 Sec  Memory Limit: 256 MBSubmit: 2131  Solved: 865[Submit][Statu ...

  2. 八. 输入输出(IO)操作2.面向字符的输入流

    字符流是针对字符数据的特点进行过优化的,因而提供一些面向字符的有用特性,字符流的源或目标通常是文本文件. Reader和Writer是java.io包中所有字符流的父类.由于它们都是抽象类,所以应使用 ...

  3. Oracle PL/SQL入门之慨述

    Oracle PL/SQL入门之慨述 一.PL/SQL出现的目的 结构化查询语言(Structured Query Language,简称SQL)是用来访问关系型数据库一种通用语言,它属于第四代语言( ...

  4. 监控SQL Server正在执行的SQL语句和死锁情况

    原文:监控SQL Server正在执行的SQL语句和死锁情况 SELECT [Individual Query] = SUBSTRING(qt.TEXT, er.statement_start_off ...

  5. What is Mocking?

    Mocking is primarily used in unit testing. An object under test may have dependencies on other (comp ...

  6. 【SVN】删除SVN上的历史资源路径和SVN上的历史用户信息

    1.删除svn上历史资源路径 window--show view--other--svn资源库 可以右键选择删除 . ----------------------------------------- ...

  7. SQL Server 系统函数

    一组内置函数,对 SQL Server 中的值.对象和设置执行操作,并返回有关它们的信息.   系统函数 功能 APP_NAME() 返回当前会话的应用程序名称(如果应用程序进行了设置) CASE表达 ...

  8. ARCGIS FLEX API加载google地图、百度地图、天地图(转)

    http://www.cnblogs.com/chenyuming507950417/ Flex加载google地图.百度地图以及天地图作底图 一  Flex加载Google地图作底图 (1)帮助类G ...

  9. androidmanifest

    在unity里面这个androidmanifest.xml 就相当于 buildsetting 里面的playersettings

  10. 前后台JSON传值得一个问题和异常处理net.sf.json.JSONException: Unquotted string '"name"'

    项目中做导入的时候遇到个bug,用JSON.stringify()序列号json对象传给后台:然后后台通过getPatameter()获取值时,前台的英文引号变成了中文引号. 原来代码如下:(自己排查 ...