Topics requirements:
Planet X Angry Birds hit like a train! On a train between two flat tracks 1000 m apart. Two trains (referred wish A and B) at a speed of 10 m / sec with a relative. A car from angry birds starting speed of 50 m / sec, crashed car B, then return the car run into the A, B car run into the back, .... and so forth of the two trains stop at a distance of 1 meter.
Q: During this period hit Angry Birds B car How many times?
Note: You need to submit is an integer (B represents the number of hit car), do not fill anything else.
package org.bluebridge.topics;
public class Main {
static int i = 0; //次数的两倍
static int time = 0;//碰撞B车的速度
public static double dis(double length) { //两车相距的距离
double t = length / 60; //第一次恰好碰撞的时间
length = length - 2 * t * 10; //第一次碰撞时小鸟从A车走到B车后两车的距离
//满足条件,返回结果
if (length <= 1) {
return 0;
}
//因为小鸟来回碰撞A和B车,题目只要求碰撞B车的次数,所以要除以2
if (i % 2 == 0) {
time++;
}
i++;
return dis(length);//递归深搜
}
public static void main(String[] args) {
dis(1000);//从最长距离1000逐渐减少两车之间的距离
System.out.println(time);
}
}
The answer is: 9