当前位置:   article > 正文

蓝桥杯-龟兔赛跑预测(Java)_龟兔赛跑预测 蓝桥杯java

龟兔赛跑预测 蓝桥杯java

龟的时间就是l/v2

兔的时间是多方面因素决定的,可以假设它每跑m米就休息s秒,m=乌龟超过它的距离+t

  1. import java.util.Scanner;
  2. public class Main{
  3. public static void main(String[] args){
  4. Scanner scanner = new Scanner(System.in);
  5. int v1 = scanner.nextInt();
  6. int v2 = scanner.nextInt();
  7. int t = scanner.nextInt();
  8. int s = scanner.nextInt();
  9. int l = scanner.nextInt();
  10. scanner.close();
  11. System.out.println(getResult(v1, v2, t, s, l));
  12. }
  13. private static String getResult(int vRabbit, int vTurtle, int leadDist, int timeRest, int raceLength){
  14. int timeTurtle = raceLength / vTurtle;
  15. int timeRabbit = 0;
  16. int remainLength = raceLength;
  17. int turtlePassDist = 0;
  18. while (true){
  19. int t = (int)(Math.ceil((1.f * turtlePassDist + leadDist) / (vRabbit - vTurtle)));
  20. int currLength = t * vRabbit;
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/64369?site
推荐阅读
相关标签
  

闽ICP备14008679号