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

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

代码:

 #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. HD1285(拓扑排序)

    package cn.hncu.dataStruct.search.topSort; import java.util.Scanner; public class Hdu1285 { static S ...

  2. Android开发JDBC连接mysql数据库导入驱动方法

    在使用JDBC编程时需要连接数据库,导入JAR包是必须的,导入其它的jar包方法同样如此,导入的方法是 打开eclipse 1.右击要导入jar包的项目,点properties 2.左边选择java ...

  3. Java Interface and Abstraction

    本文引用资源申明: http://blog.csdn.net/xw13106209/article/details/6923556 http://www.cnblogs.com/dolphin0520 ...

  4. 深入理解计算机系统第二版习题解答CSAPP 2.1

    A.将0x39A7F8转换为二进制. 0011 1001  1010 0111  1111 1000 B.将二进制1100 1001 0111 1011转换为十六进制. 0xC97B C.将0xD5E ...

  5. PHP + ajax 实现异步登录验证

    login.html: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:/ ...

  6. Yii框架页面运行流程

    Yii框架页面运行流程 CComponent | CModel | CActiveRecord.CFormModel(所有模型的父类) | 表名.php(模型) | 入口文件------------- ...

  7. Dev ComboxTree的实现

    一个项目中刚好用到,自己做下笔记备份 顺便和大家共享下 需要用到ASPxDropDownEdit ASPxTreeView 这两个控件 ASPxDropDownEdit对应的dll为:DevExpre ...

  8. T-SQL基础 (子查询,连接查询,交叉查询,事务|| 笔记0807)

    一: A.子查询: 1.select 字段名 from table where 字段名=(select 字段名 from table 条件)  //只能做1个匹配 2.select 字段名 from ...

  9. CSS 隐藏多余的字符

    日常开发中常常会碰到,字符长度太大,撑破了样式的问题.如果采用截取的话,显然是不灵活的.但是通过css样式来控制显示就比较简单和高效了.下面是关键代码 样式名称{wedth:??px;height=? ...

  10. WPF:保存窗口当前状态截图方法

    在制作软件使用手册或者操作示范市,比较常用方式有截图和视频制作.如果软件内置当前状态的截图和操作视频的导出功能,则将极大简化这方面的工作.使用wpf编写的UI界面,截图的导出功能逻辑相对简单,通用的实 ...