• 10881


    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 horizontalpole L cm long. Each ant is facing either left or right and walksat a constant speed of 1 cm/s. When two ants bump into each other, theyboth turn around (instantaneously) and start walking in opposite directions.Piotr knows where each of the ants starts and which direction it is facingand wants to calculate where the ants will end up T seconds from now.

    Input
    The first line of input gives the number of cases, N. Ntest 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 (measuredin 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 then ants in the same format and order as in the input. If two or moreants are at the same location, print "Turning" instead of "L" or "R" fortheir 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 Input Sample 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
    
    
    #include<iostream>
    #include<algorithm>
    using namespace std;
    struct data{int x;char u;int o;}p[10005];
    int temp(void const *p,void const *q)
    {
    	return (*(data *)p).x-(*(data *)q).x;
    }
    
    int main()
    {
    	int N,l,t,n,count=1;
    	cin>>N;
    	while(N--)
    	{
    		int order[10005]={0};
    		cin>>l>>t>>n;
    		for(int i=0;i<n;i++)
    		{
    			cin>>p[i].x>>p[i].u;
    			p[i].o=i;
    		}
    		qsort(p,n,sizeof(p[0]),temp);
    		for(int i=0;i<n;i++)
    			order[p[i].o]=i;
    		for(int i=0;i<n;i++)
    			if(p[i].u=='L') p[i].x-=t;
    			else p[i].x+=t;
    			qsort(p,n,sizeof(p[0]),temp);
    			for(int i=0;i<n-1;i++)
    				if(p[i].x==p[i+1].x)
    				{
    					p[i].u='T';
    					p[i+1].u='T';
    				}
    				cout<<"Case #"<<count++<<":"<<endl;
    				for(int i=0;i<n;i++)
    				{
    					int a=order[i];
    					if(p[a].x<0||p[a].x>l) cout<<"Fell off"<<endl;
    					else 
    					{
    						cout<<p[a].x<<" ";
    						if(p[a].u=='T') cout<<"Turning"<<endl;
    						else cout<<p[a].u<<endl;
    					}
    				}
    				cout<<endl;
    	}
    	return 0;
    }


  • 相关阅读:
    Linux系统挂载NTFS移动硬盘
    ActiveReport报表开发谈谈ActiveReport的中文化问题
    硬件接口开发之USB电话录音盒来电显示
    如何使用正则表达式进行QQ校友的数据采集
    硬件接口开发之Modem来电显示
    关于MSHTML控件使用的问题
    【转】ISession接口介绍
    发送带嵌入图片邮件之SMTP实现和ESMTP实现
    C#进行MapX二次开发之地图搜索
    Database2Sharp混淆处理之经验分享(国庆专辑,祝福我们的祖国)
  • 原文地址:https://www.cnblogs.com/snake-hand/p/3141321.html
Copyright © 2020-2023  润新知