zoukankan      html  css  js  c++  java
  • Java实现 洛谷 P1426 小鱼会有危险吗

    在这里插入图片描述

    import java.util.LinkedList;
    import java.util.Scanner;
     
    public class Main {
    	private static Scanner cin;
    	private static LinkedList<String> list;
    	private static int initSpeed = 7;
    	private static double percent = 0.98;
    	private static int x = 0;
    	private static int s = 0;
    	
    	public static void main(String args[]) throws Exception {
    		cin = new Scanner(System.in);
    		s = cin.nextInt();
    		x = cin.nextInt();
    		calc(0,initSpeed);
    	}
     
    	public static void calc(double distanceOver, double curSpeed) {
    		//首先判断是否已进入检测范围
    		if(distanceOver > (s-x)) {
    			if((distanceOver +curSpeed)<=s+x) {
    				System.out.println("y");
    				return;
    			}else {
    				System.out.println("n");
    				return;
    			}
    		}
    		//检测走一步后是否进入检测范围
    		if((distanceOver +curSpeed) > (s-x)) {
    			if((distanceOver +curSpeed*(1+percent))<=s+x) {
    				System.out.println("y");
    				return;
    			}else {
    				System.out.println("n");
    				return;
    			}
    		}else {
    			calc((distanceOver+curSpeed),curSpeed*percent);
    		}
    	}
    	
    }
    
  • 相关阅读:
    进程、线程、协程
    python垃圾回收机制
    python变量存储和深浅拷贝
    Linux常用命令
    二叉树四种遍历,节点个数,深度
    装饰器
    ArrayList、Vector
    集合、Collection、迭代器、List
    卖票
    关于Thread和Runnable
  • 原文地址:https://www.cnblogs.com/a1439775520/p/13076780.html
Copyright © 2011-2022 走看看