#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. ip接口调用

    <?php header("Content-type: text/html; charset=utf-8"); function getIP(){ if (isset($_S ...

  2. Java设计模式(学习整理)---单例模式

    1.概念: java中单例模式是一种常见的设计模式,单例模式分三种:懒汉式单例.饿汉式单例.登记式单例三种. 单例模式有一下特点: 1.单例类只能有一个实例. 2.单例类必须自己自己创建自己的唯一实例 ...

  3. 344. Reverse String(C++)

    344. Reverse String Write a function that takes a string as input and returns the string reversed. E ...

  4. javascript--自己用的插件

    /** * Created by Administrator on 2015/4/2. * 时间:2012-6-6 作用:一对form标签下有多个(包括一个)表单需要提交时,提交当前作用域中的表单项做 ...

  5. 一些javascript免费中文书籍

    在这里谢谢那些无私的人~~这些内容来自这里:我只把js的链接粘到这里了~ 还有其它技术文档, 实在是太多了, 多的看都看不完!!! Google JavaScript 代码风格指南 Google JS ...

  6. C# winform 右下角弹窗

    [DllImport("user32")] private static extern bool AnimateWindow(IntPtr hwnd, int dwTime, in ...

  7. Html5的<button>标签

    1.标签是双标签,其内可添加文字,图片等复杂的样式. ​2.不仅可以在表单中使用,还可以在其他块元素和内联元素中使用. 3.一般在input标签内添加name属性,否则提交后不显示.

  8. Android 视图切换库的使用 - SwitichLayout

    要点: 1. SwitichLayout 原理和基本特效展示 - 设计上和基本特效 2. SwitchLayout 的用法 - SwitchLayout 的基本配置和用法 3. SwithLayout ...

  9. day2练习题

    #import <Foundation/Foundation.h> int main(int argc, const char * argv[]) { @autoreleasepool { ...

  10. c# 無彈窗调用打印机

    using System; using System.Collections.Generic; using System.Text; using System.Configuration; using ...