设为首页 加入收藏

TOP

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

 

  {

  int N, L, T, n, i, position, change_c, cnt = 1;

  char c;

  cin>>N;

  while(N--)

  {

  cin>>L>>T>>n;

  for(i = 0; i < n; i++)

  {

  cin>>position>>c;

  if(c == 'L') change_c = -1; //转一下,等下计算终态与输出都方便

  else change_c = 1;

  before[i] = (ant){i, position, change_c};

  after[i] = (ant){0, position + T*change_c, change_c}; //计算终态,其中id无太大用处,可赋个默认值

  }

  sort(before, before+n); //按位置排序

  for(i = 0; i < n; i++) order[before[i].id] = i; //赋值,使输入的第i只蚂蚁是位置上的第order[i]只

  sort(after, after+n); //按位置排序

  for(i = 0; i < n-1; i++) //修改方向

  if(after[i].pos == after[i+1].pos)

  {

  after[i].dir = 0;

  after[i+1].dir = 0;

  }

  cout<<"Case #"<< xml:namespace prefix = cnt++<<" />

  for(i = 0; i < n; i++)

  {

  int a = order[i]; //输入的第i只为位置上的第a只

  if(after[a].pos < 0 || after[a].pos > L) cout<<"Fell off"<

  else cout<

      

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

评论

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