zoukankan      html  css  js  c++  java
  • 2016蘑菇街编程题:搬圆桌

    题目描述

    现在有一张半径为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
    解题
    每次移动的返回是(0,2r]
    然后感觉这就是两个圆心距离除以2r 向上取整,然后看讨论就是这样写的
    import java.util.Scanner;
    public class Main {
        public static void main(String[] args) {
            Scanner cin = new Scanner(System.in);
            while (cin.hasNextInt()) {
                int r = cin.nextInt();
                if (r < 1 || r > 100000) {
                    System.exit(0);
                }
                int x = cin.nextInt();
                int y = cin.nextInt();
                int x1 = cin.nextInt();
                int y1 = cin.nextInt();
                if (x < -100000 || x > 100000) {
                    continue;
                }
                if (y < -100000 || y > 100000) {
                    continue;
                }
                if (x1 < -100000 || x1 > 100000) {
                    continue;
                }
                if (y1 < -100000 || y1 > 100000) {
                    continue;
                }
                double length = Math.sqrt(Math.pow(x - x1, 2) + Math.pow(y - y1, 2));
                int count;
                //向上取整之后强转为int型即可
                count = (int) Math.ceil(length / (2 * r));
                System.out.println(count);
            }
        }
    }


  • 相关阅读:
    在rhel6上安装Python 2.7和Python 3.3
    RHEL7 -- Linux搭建FTP虚拟用户
    RHCE7 -- IPv6
    RHEL7 -- nmcli的使用
    设置Adobe Reader打开PDF文件保持记忆功能
    iptalbes -F
    服务器IP地址后修改SQL Server配置
    配置SELINUX
    11G新特性 -- 分区表和增量统计信息
    11G新特性 -- Statistics Preferences
  • 原文地址:https://www.cnblogs.com/theskulls/p/5337812.html
Copyright © 2011-2022 走看看