本文主要是介绍2059.龟兔赛跑,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
主要注意乌龟可以选择不充电
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;public class Main {public static void main(String[] args) throws IOException {BufferedReader bufferedReader=new BufferedReader(new InputStreamReader(System.in));String first=bufferedReader.readLine();while (!first.equals("")){String []second= bufferedReader.readLine().split(" ");String []third=bufferedReader.readLine().split(" ");String []fourth= bufferedReader.readLine().split(" ");int l=Integer.parseInt(first);//跑道的总长int n=Integer.parseInt(second[0]);//充电站的个数int c=Integer.parseInt(second[1]);//电动车冲满电以后能行驶的距离int t=Integer.parseInt(second[2]);//每次充电所需要的时间double vr=Double.parseDouble(third[0]);//兔子跑步的速度double vt1=Double.parseDouble(third[1]);//乌龟开电动车的速度double vt2=Double.parseDouble(third[2]);//乌龟脚蹬电动车的速度int []p=new int[n];for (int i=0;i<n;i++){p[i]=Integer.parseInt(fourth[i]);}double timeR=l/vr;double timeT=0;int curdist=0;int curelec=c;for (int i=0;i<n;i++){if (p[i]-curdist>c){timeT+=c/vt1;timeT+=(p[i]-curdist-c)/vt2;curdist=p[i];curelec=c;timeT+=t;}else {timeT+=(p[i]-curdist)/vt1;curdist=p[i];curelec-=(p[i]-curdist);if (i<n-1){if (curelec+curdist<p[i+1]){timeT+=t;curelec=c;}}}}if (timeR<timeT){System.out.println("Good job,rabbit!");}else {System.out.println("What a pity rabbit!");}first=bufferedReader.readLine();}}
}
这篇关于2059.龟兔赛跑的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!