时间限制: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. HDOJ 3516 Tree Construction 四边形优化dp

    原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=3516 题意: 大概就是给你个下凸包的左侧,然后让你用平行于坐标轴的线段构造一棵树,并且这棵树的总曼哈顿 ...

  2. luogu P1041 传染病控制

    题目背景 近来,一种新的传染病肆虐全球.蓬莱国也发现了零星感染者,为防止该病在蓬莱国大范围流行,该国政府决定不惜一切代价控制传染病的蔓延.不幸的是,由于人们尚未完全认识这种传染病,难以准确判别病毒携带 ...

  3. [Git]Git 常用的操作命令

    创建本地仓库 git init 获取远程仓库 git clone [url] 例如:git clone https://github.com/you/yourpro.git 创建远程仓库 添加一个新的 ...

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

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

  5. Nand 的几个名词:oob,bbt,ecc

    转:http://blog.csdn.net/lanmanck/article/details/4230904 例如Samsung K9F1208U0B,数据存储容量为64MB,采用块页式存储管理.8 ...

  6. 【微信】微信小程序 微信开发工具 创建js文件报错 pages/module/module.js 出现脚本错误或者未正确调用 Page()

    创建报错pages/module/module.js 出现脚本错误或者未正确调用 Page() 解决方法: 在js文件中添加 Page({ })

  7. iis7文件夹 首页设置

    iis7在默认文档中可以设置首页,一般可以直接设置网站根目录下的页面为首页,但是当页面不在根目录下时,直接按路径添加就不行了,如“admin/default.aspx”.添加完后只有“default. ...

  8. 什么是HotSpot VM & 深入理解Java虚拟机 JVM

    参考 http://book.2cto.com/201306/25434.html 另外,这篇文章也是从一个系列中得出的: <深入理解Java虚拟机:JVM高级特性与最佳实践(第2版)> ...

  9. Bean的作用域scope

    Bean的作用域scope 1.singleton 单例,指一个bean容器中只存在一份 2.prototype 每次请求(每次使用)创建新的实例,destroy方式不生效 3.request 每次h ...

  10. 权重轮询调度算法(WeightedRound-RobinScheduling)-Java实现3

    权重轮询调度算法(WeightedRound-RobinScheduling)-Java实现3 之前两篇相关博文: 权重轮询调度算法(WeightedRound-RobinScheduling)-Ja ...