BNU19299 UVA10881 Piotr's Ants

Time Limit: 3000ms
Memory Limit: 131072KB
This problem will be judged on  UVA. Original ID:  10881
64-bit integer IO format:  %lld      Java class name:  Main
Type: 
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •                   
  • [PDF Link]

    Problem D
    Piotr's Ants
    Time Limit: 2 seconds

    "One thing is for certain: there is no stopping them;
    the ants will soon be here. And I, for one, welcome our
    new insect overlords."
    Kent Brockman

    Piotr likes playing with ants. He has n of them on a horizontal pole L cm long. Each ant is facing either left or right and walks at a constant speed of 1 cm/s. When two ants bump into each other, they both turn around (instantaneously) and start walking in opposite directions. Piotr knows where each of the ants starts and which direction it is facing and wants to calculate where the ants will end up T seconds from now.

    Input
    The first line of input gives the number of cases, NN test cases follow. Each one starts with a line containing 3 integers: L , T and n  (0 <=  n <= 10000) . The next n lines give the locations of the n ants (measured in cm from the left end of the pole) and the direction they are facing (L or R).

    Output
    For each test case, output one line containing "Case #x:" followed by n lines describing the locations and directions of the n ants in the same format and order as in the input. If two or more ants are at the same location, print "Turning" instead of "L" or "R" for their direction. If an ant falls off the pole before T seconds, print "Fell off" for that ant. Print an empty line after each test case.

    Sample InputSample Output
    2
    10 1 4
    1 R
    5 R
    3 L
    10 R
    10 2 3
    4 R
    5 L
    8 R
    
    Case #1:
    2 Turning
    6 R
    2 Turning
    Fell off
    
    Case #2:
    3 L
    6 R
    10 R

    https://www.bnuoj.com/v3/problem_show.php?pid=19299

    一根长度为L厘米的木棍上有n只蚂蚁,每只蚂蚁要么朝左爬,要么朝又爬,速度为1厘米/秒.当两只蚂蚁相撞时,二者同时掉头(掉头时间忽略不计).给出每只蚂蚁的初始和朝向,计算T

    秒之后每只蚂蚁的位置.

    按输入顺序输出每只蚂蚁的位置和朝向(Turning表示正在碰撞).在第T秒之前已经掉下木棍的边缘的不算)输出Fell off.

    从远处看就是一群密密麻麻的小黑点在移动  由于碰撞掉头时间不会耗时相当于两个点"对穿而过" 没有任何的影响

    输入的时候不一定按顺序 按输入的输出

    关键是要弄清楚最后的时刻  哪只蚂蚁是刚开始的哪只

    #include<bits/stdc++.h>
    using namespace std;
    struct point
    {
        int h,d,w;
        friend bool operator < (point a,point b)
        {
            if(a.h==b.h)
                return a.d<b.d;
            else return a.h<b.h;
        }
    } aa[10010],bb[10010];
    
    int cmp(point a,point b)
    {
        return a.w<b.w;
    }
    
    int main()
    {
        int kk=0,i,tt,l,t,n;
        char gg;
        scanf("%d",&tt);
        while(tt--)
        {
            printf("Case #%d:\n",++kk);
            scanf("%d%d%d",&l,&t,&n);
            for(i=0; i<n; i++)
            {
                scanf("%d %c",&aa[i].h,&gg);
                aa[i].w=i;//记录位置
                if(gg=='R')
                    aa[i].d=1;
                else aa[i].d=-1;
            }
            sort(aa,aa+n);//排到在木棍上的位置
            for(i=0; i<n; i++)
            {
                bb[i].h=aa[i].h+aa[i].d*t;
                bb[i].d=aa[i].d;
            }
            sort(bb,bb+n);
            bb[n].h=-1;
            for(i=0;i<n;i++)
        if(bb[i].h==bb[i+1].h||bb[i].h==bb[i-1].h)
            bb[i].d=2;
            for(i=0; i<n; i++)
            {
                aa[i].h=bb[i].h;
                aa[i].d=bb[i].d;
            }
            sort(aa,aa+n,cmp);//按原来位置回来
            for(i=0; i<n; i++)
            {
                if(aa[i].h<0||aa[i].h>l)
                    printf("Fell off\n");
                else if(aa[i].d==2)
                    printf("%d Turning\n",aa[i].h);
                else
                {
                    if(aa[i].d==-1)
                        printf("%d L\n",aa[i].h);
                    else printf("%d R\n",aa[i].h);
                }
            }
            printf("\n");
        }
        return 0;
    }
    

    • 0
      点赞
    • 0
      收藏
      觉得还不错? 一键收藏
    • 0
      评论

    “相关推荐”对你有帮助么?

    • 非常没帮助
    • 没帮助
    • 一般
    • 有帮助
    • 非常有帮助
    提交
    评论
    添加红包

    请填写红包祝福语或标题

    红包个数最小为10个

    红包金额最低5元

    当前余额3.43前往充值 >
    需支付:10.00
    成就一亿技术人!
    领取后你会自动成为博主和红包主的粉丝 规则
    hope_wisdom
    发出的红包
    实付
    使用余额支付
    点击重新获取
    扫码支付
    钱包余额 0

    抵扣说明:

    1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
    2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

    余额充值