时间限制: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. #请用索引取出下面list的指定元素:

    #!/usr/bin/python # -*- coding: utf-8 -*- L = [ ['Apple', 'Google', 'Microsoft'], ['Java', 'Python', ...

  2. 四. Java继承和多态4. 多态和动态绑定

    在Java中,父类的变量可以引用父类的实例,也可以引用子类的实例. 请读者先看一段代码: public class Demo { public static void main(String[] ar ...

  3. ReactNative学习笔记1 Flexbox布局

    一.比例属性flex和布局方向属性flexDirection 例如三个视图的flex属性值分别为2.4.8,则它们的高度比例为2:4:8.,宽度不指定,默认为全屏的宽度. class ZLFReact ...

  4. sql server mvp 听风吹雨

    http://www.cnblogs.com/gaizai/p/4087321.html

  5. sql server 老外博客

    Aaron Bertrand Grant Fritchey Brent Ozar Thomas LaRock Pinal Dave Phil Factor SQL Skills w/ Paul Ran ...

  6. iOS教程:如何使用Core Data – 预加载和引入数据

    这是接着上一次<iOS教程:Core Data数据持久性存储基础教程>的后续教程,程序也会使用上一次制作完成的. 再上一个教程中,我们只做了一个数据模型,之后我们使用这个数据模型中的数据创 ...

  7. Request Header Or Cookie Too Large

    运营反馈 Nginx 报 400 错误,具体点说:Request Header Or Cookie Too Large.其实随便搜搜就知道可以通过加大 client_header_buffer_siz ...

  8. ruby ide

    uby 是个动态面向对象.通用的编程语言.它支持多种编程范式,包括面向功能和面向对象.同时它也包括一个动态类型系统和自动内存管理. 编辑器和集成开发环境(IDE)有些不同,编辑器是用来添加,编辑,查看 ...

  9. 【Docker】Docker管理平台 Rancher ---- 你应该学学Rancher是怎么做容器的管理的

    Elasticsearch is a Lucene-based search engine developed by the open-source vendor, elastic. With pri ...

  10. Java 学习之网络编程案例

    网络编程案例 一,概念 1,网络编程不等于网站编程 2,编程只和传输层打交道,即TCP和UDP两个协议 二,案例 1,TCP实现点对点的聊天 Server端:两个输入流:读客户端和控制台,一个输出端: ...