日期:2014-05-20  浏览次数:20687 次

关于刚才一只小鸟的问题,请大家看看
[code=C#][/code]
class Program
  {
  static double h = 100; //两地总距离
  static double s = 0; //小鸟飞行总距离 
  const int birdSpeed = 30; //小鸟飞行速度
  const int aSpeed = 20; //火车速度A
  const int bSpeed = 15; //火车速度B

  static void Main(string[] args)
  {
  for (; ; )
  {
  double time = h / (birdSpeed + aSpeed); //第一次小鸟与火车相遇所用时间
  h = h - aSpeed * time + bSpeed * time; //相遇后两火车之间距离
  if (h < 0.1) //判断是否相遇
  {
  Console.WriteLine(s);
  break;
  }
  else
  {
  s = s + birdSpeed * time; //没有相遇,累计小鸟飞行距离
  time = h / (birdSpeed + bSpeed); //飞向另一火车所用时间
  h = h - aSpeed * time + bSpeed * time; //剩余距离
  if (h < 0.1)
  {
  Console.WriteLine(s);
  break;
  }
  else s = s + birdSpeed * time;
  }
  }
  Console.ReadKey();
  }
  }

得出的总飞行距离不对. 可能是思路不对吧 . 刚才学不久别笑我啊

------解决方案--------------------
你说是这个?http://topic.csdn.net/u/20090501/01/77bc8798-90b0-4877-86a8-fc924e26bc34.html

题目都有问题你还真去做啊...这么跟你说吧,小鸟没有长度也没有给出最小步进单位,那就是线性移动了...得用线性代数和微积分求解,不是简单的加减乘除能解决的...