时间限制: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. C++大数板子

    C++大数板子 使用样例在主函数里看就好,必要的运算符都重载了. #include <iostream> using namespace std; ;/*精度位数,自行调整*/ //1.如 ...

  2. Codeforces Round #325 (Div. 2) Phillip and Trains dp

    原题连接:http://codeforces.com/contest/586/problem/D 题意: 就大家都玩过地铁奔跑这个游戏(我没玩过),然后给你个当前的地铁的状况,让你判断人是否能够出去. ...

  3. linux-网络监控命令-netstat初级

    简介 Netstat 命令用于显示各种网络相关信息,如网络连接,路由表,接口状态 (Interface Statistics),masquerade 连接,多播成员 (Multicast Member ...

  4. Chromium和Chrome的区别

    1.Chromium是谷歌的开源项目,开发者们可以共同去改进它,然后谷歌会收集改进后的Chromium并发布改进后安装包.Chrome不是开源项目,谷歌会把Chromium的东西更新到Chrome中. ...

  5. Mybatis通用分页

    分页分为真分页和假分页,而 MyBatis 本身没有提供基于数据库方言的分页功能,而是基于 JDBC 的游标分页,很容易出现性能问题.网上提供的一个解决方案感觉还不错,是基于 MyBatis 本身的插 ...

  6. jstl的错误总结与解决方法

    哎,真他娘的无语了,jstl标签竟然还与tomcat的版本有关.一会报错:java.lang.AbstractMethodError: javax.servlet.jsp.PageContext.ge ...

  7. 机器学习算法实践:决策树 (Decision Tree)(转载)

    前言 最近打算系统学习下机器学习的基础算法,避免眼高手低,决定把常用的机器学习基础算法都实现一遍以便加深印象.本文为这系列博客的第一篇,关于决策树(Decision Tree)的算法实现,文中我将对决 ...

  8. mac 上python编译报错No module named MySQLdb

    mac 上python编译报错No module named MySQLdb You installed python You did brew install mysql You did expor ...

  9. JPEG编码(二)

    来自CSDN评论区http://bbs.csdn.net/topics/190980 1. 色彩模型 JPEG 的图片使用的是 YCrCb 颜色模型, 而不是计算机上最常用的 RGB. 关于色彩模型, ...

  10. [Apollo Server] Get started with Apollo Server

    Get started with apollo server with node.js: Install: npm install --save apollo-server graphql index ...