搬桌子

现在有一张半径为r的圆桌,其中心位于(x,y),现在他想把圆桌的中心移到(x1,y1)。每次移动一步,都必须在圆桌边缘固定一个点然后将圆桌绕这个点旋转。问最少需要移动几步。

输入描述:
一行五个整数r,x,y,x1,y1(1≤r≤100000,-100000≤x,y,x1,y1≤100000)
输出描述:
输出一个整数,表示答案

输入例子:
2 0 0 0 4

输出例子:
1
import java.util.Scanner;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner s = new Scanner(System.in);
//		System.out.println(50466*50466);
		while(s.hasNext()){
			String rstr = s.next();
			int r = Integer.parseInt(rstr);
			String xstr = s.next();
			int x = Integer.parseInt(xstr);
			String ystr = s.next();
			int y = Integer.parseInt(ystr);
			String x1str = s.next();
			int x1 = Integer.parseInt(x1str);
			String y1str = s.next();
			int y1 = Integer.parseInt(y1str);
			Table t = new Table();
			System.out.println(t.move(r, x, y, x1, y1));
		}	
	}

}
class Table{
	public int move(int r, int x, int y, int x1, int y1){//返回值:需要移动桌子的次数
//		(x,y)->(0,0)  (x1,y1)->(x2,y2)
//		double r0 = (double)r;
		double x2 = x1-x;
		double y2 = y1-y;
		double d = Math.sqrt(x2*x2+y2*y2);
		
		int times = 0;
		double len = 0;
		if(d==r){
			return times;
		}
		while(len+2*r<d){//int型会超出范围
			times++;
			len=len+2*r;
		}
		times++;
		return times;
	}
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值