zoukankan      html  css  js  c++  java
  • 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;
    }


  • 相关阅读:
    读书是最划算的自我投资,免费送几本最好的Python学习电子书
    一个出身寒门的状元之编程
    幼儿园小朋友都在学人工智能了,已经从小学毕业的我们该如何学?
    python语音识别终极指南
    Python可视化神器——pyecharts的超详细使用指南!
    用 Python 分析过往 36 年春晚节目数据,发现一些趣事
    拉勾网数据分析职位分析
    按时分秒对数据进行分箱
    numpy
    基于协同过滤的推荐系统案列
  • 原文地址:https://www.cnblogs.com/snake-hand/p/3141321.html
Copyright © 2011-2022 走看看