zoukankan      html  css  js  c++  java
  • uva 10881

    这个题的突破点就在于蚂蚁不能够穿过对方,故相对位置不变;

    另外,又可以把蚂蚁看成运动方向不变;

    代码:

     1 #include<cstdio>
     2 #include<algorithm>
     3 using namespace std;
     4 #define maxn 10005
     5 
     6 char dir[][10]={"L","Turning","R"};
     7 
     8 int order[maxn];
     9 
    10 struct ant
    11 {
    12     int id,p,d;
    13     bool operator<(const ant &t)const
    14     {
    15         return p<t.p;
    16     }
    17 }st[maxn],now[maxn];
    18 
    19 int main()
    20 {
    21     int t,n,ti,l,ca=1,p,d;
    22     char c;
    23     scanf("%d",&t);
    24     while(t--)
    25     {
    26         printf("Case #%d:
    ",ca++);
    27         scanf("%d%d%d",&l,&ti,&n);
    28         for(int i=0;i<n;i++)
    29         {
    30             scanf("%d %c",&p,&c);
    31             d=(c=='L'?-1:1);
    32             st[i]=(ant){i,p,d};
    33             now[i]=(ant){0,p+ti*d,d};
    34         }
    35         sort(st,st+n);
    36         for(int i=0;i<n;i++)
    37             order[st[i].id]=i;
    38         sort(now,now+n);
    39         for(int i=0;i<n-1;i++)
    40             if(now[i].p==now[i+1].p)
    41                 now[i].d=now[i+1].d=0;
    42         for(int i=0;i<n;i++)
    43         {
    44             int a=order[i];
    45             if(now[a].p<0||now[a].p>l)puts("Fell off");
    46             else printf("%d %s
    ",now[a].p,dir[now[a].d+1]);
    47         }
    48         printf("
    ");
    49     }
    50     return 0;
    51 }
    View Code
  • 相关阅读:
    H3C 配置vlan及vlan间路由
    H3C 端口安全技术
    H3C 备份系统应用程序与文件
    H3C 类似于Linux编辑命令
    H3C telnet
    H3C基本命令
    Python里的目录
    Python 模块
    Python 函数
    JS 100内与7相关的数
  • 原文地址:https://www.cnblogs.com/yours1103/p/3388784.html
Copyright © 2011-2022 走看看