#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. Android开发--去掉标题栏

    Android开发中为了尽可能美观,会去掉标题栏.去掉标题栏有三种方法. 一.在Activity代码里实现 在代码中实现以下方法: this.requestWindowFeature(Window.F ...

  2. java web(jsp)-The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path

    在静态项目上新建 jsp文件的时候,报错:The superclass "javax.servlet.http.HttpServlet" was not found on the ...

  3. sql数值显示成千分位分隔符的形式

    ), )--带小数点 ), ),'.00','')--不带小数点

  4. Linux下sqlite的安装与使用

      简介 SQLite是一款轻量级数据库,是遵守ACID的关联式数据库管理系统.它的设计目的是嵌入式.目前已经在很多嵌入式产品中使用了它,它占用资源非常的低,在嵌入式设备中,可能只需要几百KB的内存就 ...

  5. linux设置中文环境

    确认当前环境 [root@Oracle11g ~]# df –h Filesystem            Size  Used Avail Use% Mounted on /dev/sda1    ...

  6. javascript事件详解1

    事件流讲解来袭,嘎嘎嘎嘎嘎 ---------------------------------------------------------------- 1.事件流:描述的是在页面中接受事件的顺序 ...

  7. java常用指令

    javac 编译java源文件到字节码文件 -d XXX 1.指定编译后的字节码文件存放位置. 2.若编译的java源文件中使用包名,则根据包名生成相应的子目录 javac -d . Hello.ja ...

  8. C++ Reference 的“三位一体”诠释

    C++ 是介于汇编语言与高级语言之间的一种“全能”语言.它的能力是其他任何基于VMA(冯-诺曼架构)计算机的高级程序设计语言无法望其项背的,而性能也只有C语言可与之伯仲. 然而长期以来,喜欢C++和憎 ...

  9. jQuery慢慢啃之属性(三)

    1.attr(name|properties|key,value|fn)设置或返回被选元素的属性值. $("img").attr("src");//获取属性 $ ...

  10. windows编程中 一些前缀区分 IDR和IDD

    IDC_:控件的ID命名前缀(Control) IDM_:菜单的ID命名前缀(Menu) IDD_:对话框的ID命名前缀(Dialog) IDR_:资源的ID命名前缀(Resource) IDS_:字 ...