zoukankan      html  css  js  c++  java
  • 搬圆桌问题

    现在有一张半径为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;所以

    移动的步数 = 两圆心的距离-直径

    代码

    //#include "stdafx.h"
    #include <iostream>
    #include <string>
    #include <vector>
    #include <math.h>
    #include<stack>
    #include <stdio.h>
    //#include <conio.h>
    #include <stdlib.h>
    #include <time.h>
    using namespace std;
    
    
    
    
    #include <stdio.h>
    
    
    int f(double r,double x,double y,double x1,double y1)
    {
        double x2 ;
        double y2;
        x2 = x1-x;
        y2 = y1-y;
        
        double d;
        d = sqrt(x2*x2+y2*y2);
        
        int ret = 0;
        ret =(int) d/(2*r);
        return ret;
        
        
    }
    
    
    
    
    int main()
    {
       double r;
       double x;
       double y;
       double x1;
       double y1;
        
        
        while(cin>>r>>x>>y>>x1>>y1)
        {
             int s = 0;
        s = f(r,x,y,x1,y1);
        
        cout << s << endl;    
            
        }
        
        
       
        return 0;    
        
    }

    当然了,头文件存在没有使用的情况。

  • 相关阅读:
    python 模块包裹
    函数指针
    python界面
    python FileError
    python pickle
    python file
    python set
    python 字典的函数
    字典问题
    java学习笔记4
  • 原文地址:https://www.cnblogs.com/china-sdd/p/6647026.html
Copyright © 2011-2022 走看看