设为首页 加入收藏

TOP

蚂蚁相撞问题实例(一)
2013-05-14 09:23:40 来源: 作者: 【 】 浏览:677
Tags:蚂蚁 相撞 问题 实例

  过程中两个思想:1、两只蚂蚁相撞后假设互穿而过得最终各蚂蚁位置;2、终态各蚂蚁的相对位置不变,与始态相同。

  [cpp]

  #include

  #include

  using namespace std;

  const int maxn = 10000 + 10;

  struct ant //定义蚂蚁数据类型

  {

  int id; //输入时的id编号,从0开始计数

  int pos; //距左端的位置

  int dir; //方向

  bool operator < (const ant &a) const //重载运算符,按位置前后为序

  {

  return pos < a.pos;

  }

  };

  ant before[maxn], after[maxn]; //未处理前的before,处理后为after

  const char dir_name[] = {"L", "Turning", "R"}; //方向数组

  int order[maxn]; //输入的第i只蚂蚁是位置上的第order[i]只

  int main()

   

首页 上一页 1 2 3 4 5 下一页 尾页 1/5/5
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇第一个dshow的playerdemo 下一篇排序算法之简单选择排序

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: