• 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);
    		}
    	}
    	
    }
    
  • 相关阅读:
    POJ3186(KB12-O DP)
    POJ1661(KB12-M DP)
    POJ2533(KB12-N LIS)
    POJ1458(KB12-L LCS)
    HDU1160(KB12-J DP)
    HDU1260(KB12-H DP)
    HDU1114(KB12-F DP)
    HDU1024(DP)
    HDU1074(KB12-D 状态压缩dp)
    天梯赛2016-L2
  • 原文地址:https://www.cnblogs.com/a1439775520/p/12947134.html
Copyright © 2020-2023  润新知