#include <cstdio>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <queue>
#include <vector>
#define maxn 10005
#define L -1
#define R 1
#define fell 10
#define Turning -10
#define On 0; using namespace std;
struct ants{
int location;
int direction;
int inputorder;
int state;
bool operator < (const ants& a) const{
return location <a.location;
}
}Ant[maxn]; int main(){
//if(freopen("input.txt","r",stdin)== NULL) {printf("Error\n"); exit(0);} int n,l,T;
int N;
cin>>N;
for(int test=;test<=N;test++){
cin>>l>>T>>n;
int a;
char ch;
for(int i=;i<=n;i++){
cin>>a>>ch; if(ch == 'R') Ant[i].direction = R;
else Ant[i].direction = L;
Ant[i].location = a;
Ant[i].inputorder = i;
}
sort(Ant+,Ant+n+);
int order[maxn];
for(int i=;i<=n;i++){
order[Ant[i].inputorder] = i;
} for(int i=;i<=n;i++) Ant[i].location += T * Ant[i].direction; sort(Ant+,Ant+n+); for(int i=;i<=n;i++)
if(Ant[i].location < || Ant[i].location > l)
Ant[i].state = fell;
else if(Ant[i].location == Ant[i+].location && i < n) {
Ant[i].state = Ant [i+].state = Turning;
i++;
}
else
Ant[i].state = On;
printf("Case #%d:\n",test); for(int i=;i<=n;i++){
int j = order[i];
if(Ant[j].state == fell) printf("Fell off\n");
else if(Ant[j].state == Turning){
printf("%d Turning\n",Ant[j].location);
}
else
printf("%d %c\n",Ant[j].location,Ant[j].direction == R ? 'R' : 'L'); }
printf("\n");
}
}

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

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

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

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

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

  3. 【UVa 10881】Piotr's Ants

    Piotr's Ants Porsition:Uva 10881 白书P9 中文改编题:[T^T][FJUT]第二届新生赛真S题地震了 "One thing is for certain: ...

  4. 思维题 UVA 10881 Piotr's Ants

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

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

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

  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. 【巧妙的模拟】【UVA 10881】 - Piotr's Ants/Piotr的蚂蚁

    </pre></center><center style="font-family: Simsun;font-size:14px;"><s ...

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

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

  9. 10881 - Piotr's Ants

    Problem D Piotr's Ants Time Limit: 2 seconds "One thing is for certain: there is no stopping th ...

随机推荐

  1. WinForm中的事件触发机制学习

    在一个Form窗体中拖个按钮,双击后系统自动生成代码: private void button1_Click(object sender, EventArgs e) { } 同时在窗体的Initial ...

  2. SQL Server Management Studio的对象资源管理器的使用

    1.查看 2.对象资源管理器 3.点到某个表的身上 4.出现以下图片,因为有时动态创建的触发器,刷新表下面的触发器可能不出来,所以来这里面找

  3. java Web Services搭建环境时遇到的各种问题,记录一下。 java.lang.OutOfMemoryError: PermGen space,org/apache/struts2/util/ObjectFactoryDestroyable

    情况:在同一个,myEclipes 下加载俩个项目,一个seriver端,一个client端. 必备: myEclipes    ,apache-tomcat-7.0.42,apache-tomcat ...

  4. 用sed、awk、grep同时匹配多个条件(与模式、或模式)

    同时匹配ABC 和 123:sed -n '/ABC/{/123/p}' awk '/ABC/&&/123/{ print $0 }' grep -E '(ABC.*123|123.* ...

  5. linux常用命令之ln

    ln是linux中又一个非常重要命令,它的功能是为某一个文件在另外一个位置建立一个同不的链接,这个命令最常用的参数是-s,具体用法是:ln –s 源文件 目标文件. 当我们需要在不同的目录,用到相同的 ...

  6. 绘图quartz之加水印

      实现在图片上加一个水印  并存在document的路径下  同时在手机相册中也存一份 //首先开启imageContext找到图片     UIGraphicsBeginImageContext( ...

  7. mysql数据库中编码问题(续)

    其实之前的数据库中文乱码问题并没有彻底的解决,虽然在网页上显示正常,但是在数据库中却是乱码,虽然用户看起来没问题,但是自己就遭罪了,而且也是个极大的问题 究其原因,是没注意到一点,就是数据库中表的结构 ...

  8. Codeforces Round #287 D.The Maths Lecture

    The Maths Lecture 题意:求存在后缀Si mod k =0,的n位数的数目.(n <=1000,k<=100); 用f[i][j]代表 长为i位,模k等于j的数的个数. 可 ...

  9. TaskbarCreated 消息

    托盘中的图片就通过注册这个消息来实现,系统和进程通过进程间通信发送这个消息,进程接收他

  10. phpcms(3) V9 常用函数 及 代码整理(转)

    转自http://www.cnblogs.com/Braveliu/p/5103918.html 常用函数 及 常用代码 总结如下 <;?php //转换字符串或者数组的编码 str_chars ...