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

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

代码:

 #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. Android(java)学习笔记162:Android启动过程(转载)

    转载路径为: http://blog.jobbole.com/67931/ 1. 关于Android启动过程的问题: 当按下Android设备电源键时究竟发生了什么? Android的启动过程是怎么样 ...

  2. 关于C语言中运算符优先级的一次错误

    好久没碰编程了,最近有点闲,又拾起来.做了个简单的网络测试程序,测试的时候发现有条语句老是获取不到结果.如下: if(portnumber=atoi(argv[1])>65535) portnu ...

  3. 对于POI的XSSFCell 类型问题

    1.XSSFCell.CELL_TYPE_BLANK 2.XSSFCell.CELL_TYPE_BOOLEAN 取值方式:cell.getBooleanCellValue() 3.XSSFCell.C ...

  4. SQL Server 2008 Values 新用途

    SQL Server 2008中新增功能:可以使用单个Insert命令插入多行. Create table Demo_Values (PKID int not null identity(1,1) p ...

  5. HTML5 PC、Mobile调用摄像头(navigator.getUserMedia)

    废话少说,先贴上代码 html: <div id="main" class="masthead"> <div id="face_sc ...

  6. effective c++(04)之对象使用前初始化

    对于内置类型以外的初始化责任落在构造函数身上.如下: class PhoneNumber{}; class ABEntry{ public: ABEntry( const string& na ...

  7. javascript GB2312转UTF8

    /* * GB2312转UTF8 * 例: * var xx=new GB2312UTF8(); * var Utf8=xx.Gb2312ToUtf8("你aaa好aaaaa"); ...

  8. ibatis+spring+cxf+mysql搭建webservice

    首先需必备:mysql.myeclipse6.5.apache-cxf-2.6.2 一.建数据库,库名:cxf_demo:表名:book CREATE DATABASE `cxf_demo`  --数 ...

  9. oracle 日期格式大全

    to_date("要转换的字符串","转换的格式")   两个参数的格式必须匹配,否则会报错. 即按照第二个参数的格式解释第一个参数. to_char(日期,& ...

  10. unsigned int 转 RGB

    unsigned int颜色存储格式:0xaabbggrr,其中a,b,g,r分别表示,透明度.蓝色.绿色.红色. 方法一:使用windows宏 unsigned int clr = 0x00FF00 ...