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;
}

10881 - Piotr's Ants的更多相关文章

  1. 10881 - Piotr's Ants(排序)

    题目链接:10881 - Piotr's Ants 题目大意:在一个长为L的木棒上有n只蚂蚁,给出蚂蚁的初始位置以及方向,问说移动T秒后各个蚂蚁的位置以及状态,如果两只蚂蚁在移动的过程中相撞,则会同时 ...

  2. UVA.10881 Piotr's Ants (思维题)

    UVA.10881 Piotr's Ants (思维题) 题意分析 有一根长度为L cm的木棍,上有n只蚂蚁,蚂蚁要么向左爬,要么向右,速度均为1cm/s,若2只蚂蚁相撞,则蚂蚁同时调头.求解第T秒时 ...

  3. 思维题 UVA 10881 Piotr's Ants

    题目传送门 /* 题意:在坐标轴上一群蚂蚁向左或向右爬,问经过ts后,蚂蚁的位置和状态 思维题:本题的关键1:蚂蚁相撞看作是对穿过去,那么只要判断谁是谁就可以了 关键2:蚂蚁的相对位置不变 关键3:o ...

  4. cogs 1456. [UVa 10881,Piotr's Ants]蚂蚁

    1456. [UVa 10881,Piotr's Ants]蚂蚁 ★   输入文件:Ants.in   输出文件:Ants.out   简单对比时间限制:1 s   内存限制:128 MB [题目描述 ...

  5. POJ 1852 Ants || UVA 10881 - Piotr's Ants 经典的蚂蚁问题

    两题很有趣挺经典的蚂蚁问题. 1.n只蚂蚁以1cm/s的速度在长为L的竿上爬行,当蚂蚁爬到竿子的端点就会掉落.当两只蚂蚁相撞时,只能各自反向爬回去.对于每只蚂蚁,给出距离左端的距离xi,但不知道它的朝 ...

  6. UVA 10881 Piotr's Ants(等效变换 sort结构体排序)

    Piotr's AntsTime Limit: 2 seconds Piotr likes playing with ants. He has n of them on a horizontal po ...

  7. [ACM_模拟] UVA 10881 Piotr's Ants[蚂蚁移动 数组映射 排序技巧]

    "One thing is for certain: there is no stopping them;the ants will soon be here. And I, for one ...

  8. Uva 10881 Piotr’s Ants 蚂蚁

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

  9. uva 10881 - Piotr's Ants

    这个题的突破点就在于蚂蚁不能够穿过对方,故相对位置不变: 另外,又可以把蚂蚁看成运动方向不变: 代码: #include<cstdio> #include<algorithm> ...

随机推荐

  1. UVALive 3989 Ladies&#39; Choice

    经典的稳定婚姻匹配问题 UVALive - 3989 Ladies' Choice Time Limit: 6000MS Memory Limit: Unknown 64bit IO Format:  ...

  2. Cool Edit Pro 2.0详细教程(转)

      系统介绍一下用Cooledit pro 2.0录制自唱歌曲的一个全过程,希望对喜欢唱歌,想一展歌喉的朋友有所帮助. 录制原声 录音是所有后期制作加工的基础,这个环节出问题,是无法靠后期加工来补救的 ...

  3. 解决win7 中source insight没有courier new字节的问题

    解决win7 中source insight没有courier new字节的问题  http://blog.csdn.net/season_hangzhou/article/details/18665 ...

  4. C++自增和自减运算符(--和++)

    在C和C++中,常在表达式中使用自增(++)和自减(--)运算符,他们的作用是使变量的值增1或减1,如:++i(在使用i之前,先使i的值加1,如果i的原值为3,则执行j=++i后,j的值为4)--i ...

  5. Java--Http向服务端提交字条串数据

    package com.joye3g.http; import java.io.BufferedReader; import java.io.DataOutputStream; import java ...

  6. 你真的知道为什么不推荐使用@import?

    Difference between @import and link in CSS Use of @import <style type="text/css">@im ...

  7. AngularJS_百度百科

    AngularJS_百度百科     AngularJS    编辑     AngularJS是为克服HTML在构建应用上的不足而设计的.    目录         1简介引引        端对 ...

  8. notepad++ 配置笔记

    0.notepad++简单介绍 Notepad++是一套很有特色的自由软件的纯文字编辑器,有完整的中文化接口及支援多国语言撰写的功能.它的功能比 Windows 中的 Notepad更强大.Notep ...

  9. windows下建立文件的换行符^M导致linux下的shell脚本执行错误的解决方式

    常常在windows下编辑的文件远程传送到linux下的时候每行末尾都会出现^M.这将导致shell脚本执行错误,主要是由于dos下的编辑器和linux下的编辑器对文件末行的回车符处理不一致导致. 主 ...

  10. Delphi - XP扫雷外挂制作

    技术交流,DH讲解. 本来之前就在写这个文章,还写了War3挂的教程,后来因为一些事就没有弄了.现在过年在家又没有事就继续把这个写完吧.哈哈.不要以为写个挂很容易,要想写个挂肯定要了解游戏呀.我们现在 ...