这个题的突破点就在于蚂蚁不能够穿过对方,故相对位置不变;

另外,又可以把蚂蚁看成运动方向不变;

代码:

 #include<cstdio>
#include<algorithm>
using namespace std;
#define maxn 10005 char dir[][]={"L","Turning","R"}; int order[maxn]; struct ant
{
int id,p,d;
bool operator<(const ant &t)const
{
return p<t.p;
}
}st[maxn],now[maxn]; int main()
{
int t,n,ti,l,ca=,p,d;
char c;
scanf("%d",&t);
while(t--)
{
printf("Case #%d:\n",ca++);
scanf("%d%d%d",&l,&ti,&n);
for(int i=;i<n;i++)
{
scanf("%d %c",&p,&c);
d=(c=='L'?-:);
st[i]=(ant){i,p,d};
now[i]=(ant){,p+ti*d,d};
}
sort(st,st+n);
for(int i=;i<n;i++)
order[st[i].id]=i;
sort(now,now+n);
for(int i=;i<n-;i++)
if(now[i].p==now[i+].p)
now[i].d=now[i+].d=;
for(int i=;i<n;i++)
{
int a=order[i];
if(now[a].p<||now[a].p>l)puts("Fell off");
else printf("%d %s\n",now[a].p,dir[now[a].d+]);
}
printf("\n");
}
return ;
}

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

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

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

  2. 思维题 UVA 10881 Piotr's Ants

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

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

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

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

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

  5. 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 ...

  6. [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 ...

  7. UVA 10881 - Piotr's Ants【模拟+思维】

    题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  8. uva 10881 Piotr's Ants 解题报告

    题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=20&pa ...

  9. Uva 10881 Piotr’s Ants 蚂蚁

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

随机推荐

  1. Docker中开启sshd服务

    ssh服务安装 安装ssh服务 #yum install openssh-server -y 安装passwd(修改密码需要) #yum install passwd -y 修改sshd_config ...

  2. PowerDesigner使用详解

    PowerDesign高级应用编写相关的VBS脚本在PowerDesign里自定义一些命令与操作等,具体的可以参考C:\Program Files\Sybase\PowerDesigner 9\VB ...

  3. asterisk webrtc使用SIPML5初体验

    一直尝试,web呼叫xlite终端没有,主要是配置问题: 其中sip.conf配置如下: [general] context=public ; Default context for incoming ...

  4. jBPM开发入门指南

    http://blog.csdn.net/eric474470/article/details/7665265 工作流虽然还在不成熟的发展阶段,甚至还没有一个公认的规范标准.但其应用却已经在快速展开, ...

  5. Js 学习资料

    Js 语法 http://www.php100.com/manual/jquery/   jqGrid控件 http://www.trirand.com/blog/jqgrid/jqgrid.html

  6. Eclipse中绑定java源代码

    如何在Eclipse sdk中查看jar源代码如:*.jar  1.点 “window”-> "Preferences" -> "Java" -&g ...

  7. TS格式解析

    1.TS格式介绍 TS:全称为MPEG2-TS.TS即"Transport Stream"的缩写.它是分包发送的,每一个包长为188字节(还有192和204个字节的包).包的结构为 ...

  8. MP4(一)-结构

    http://blog.csdn.net/zhuweigangzwg/article/details/17222951 一.基本概念 1.mp4概述 MP4文件中的所有数据都装在box(QuickTi ...

  9. PeekMessage

    PeekMessage是一个Windows API函数.该函数为一个消息检查线程消息队列,并将该消息(如果存在)放于指定的结构. 1 语法 BOOL PeekMessage( LPMSG IpMsg, ...

  10. memcache的分布式算法(转)

    memcached的分布式 正如第1次中介绍的那样, memcached虽然称为“分布式”缓存服务器,但服务器端并没有“分布式”功能. 服务器端仅包括 第2次. 第3次 前坂介绍的内存存储功能,其实现 ...