蚂蚁相撞会各自回头。←可以等效成对穿而过,这样移动距离就很好算了。

末状态蚂蚁的顺序和初状态其实是相同的。

那么剩下的就是记录每只蚂蚁的标号,模拟即可。

 /*by SilverN*/
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<vector>
using namespace std;
const int mxn=;
struct ants{
int id,p,dir;
int pos;
}a[mxn];
int cmp(const ants x,const ants y){
return x.p<y.p;
}
int cmp2(const ants x,const ants y){
return x.pos<y.pos;
}
int l,t,n;
int mp[mxn];
int main(){
int T,i,j;
scanf("%d",&T);
int cas=;
while(T--){
printf("Case #%d:\n",++cas);
scanf("%d%d%d",&l,&t,&n);
char dr;
for(i=;i<=n;i++){
scanf("%d %c",&a[i].p,&dr);
if(dr=='L') a[i].dir=-;
else a[i].dir=;
}
for(i=;i<=n;i++){
a[i].id=i;
a[i].pos=a[i].p+t*a[i].dir;
}
sort(a+,a+n+,cmp);
for(i=;i<=n;i++){
mp[a[i].id]=i;
}
sort(a+,a+n+,cmp2);
for(i=;i<n;i++){
if(a[i].pos==a[i+].pos){
a[i].dir=a[i+].dir=;
}
}
for(i=;i<=n;i++){
int thi=mp[i];
if(a[thi].pos< || a[thi].pos>l){
printf("Fell off\n");continue;
}
printf("%d ",a[thi].pos);
if(a[thi].dir==-)printf("L\n");
else if(a[thi].dir==)printf("R\n");
else printf("Turning\n");
}
printf("\n");
}
return ;
}

Uva10881 Piotr's Ants的更多相关文章

  1. Uva---10881 Piotr's Ants(蚂蚁)

    Problem DPiotr's AntsTime Limit: 2 seconds "One thing is for certain: there is no stopping them ...

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

  3. 10881 - Piotr's Ants(排序)

    题目链接:10881 - Piotr's Ants 题目大意:在一个长为L的木棒上有n只蚂蚁,给出蚂蚁的初始位置以及方向,问说移动T秒后各个蚂蚁的位置以及状态,如果两只蚂蚁在移动的过程中相撞,则会同时 ...

  4. 【巧妙的模拟】【UVA 10881】 - Piotr's Ants/Piotr的蚂蚁

    </pre></center><center style="font-family: Simsun;font-size:14px;"><s ...

  5. 10881 - Piotr's Ants

    Problem D Piotr's Ants Time Limit: 2 seconds "One thing is for certain: there is no stopping th ...

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

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

  7. 【UVa 10881】Piotr's Ants

    Piotr's Ants Porsition:Uva 10881 白书P9 中文改编题:[T^T][FJUT]第二届新生赛真S题地震了 "One thing is for certain: ...

  8. 思维题 UVA 10881 Piotr's Ants

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

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

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

随机推荐

  1. 【转】$_POST 与 php://input的区别分析

    $data = file_get_contents("php://input"); php://input 是个可以访问请求的原始数据的只读流. POST 请求的情况下,最好使用 ...

  2. UML:类图复习-鸡生蛋,蛋生鸡

    这是前一阵<高级软件工程>课堂上,老师随堂出的一道讨论题,随手贴在这里: ps: 今天是520,正好聊一些OoXx,关于爱的扯淡话题:) 题目:“鸡生蛋,蛋孵鸡”,世间万物生生不息,如何用 ...

  3. Webwork 学习之路【06】Action 调用

    一路走来,终于要开始 webwork 核心业务类的总结,webwork 通过对客户端传递的 web 参数重新包装,进行执行业务 Action 类,并反馈执行结果,本篇源码分析对应下图 WebWork ...

  4. 分享:计算机图形学期末作业!!利用WebGL的第三方库three.js写一个简单的网页版“我的世界小游戏”

    这几天一直在忙着期末考试,所以一直没有更新我的博客,今天刚把我的期末作业完成了,心情澎湃,所以晚上不管怎么样,我也要写一篇博客纪念一下我上课都没有听,还是通过强大的度娘完成了我的作业的经历.(当然作业 ...

  5. c:forEach 标签中varStatus的用法

    c:forEach varStatus属性 current 当前这次迭代的(集合中的)项index  当前这次迭代从 0 开始的迭代索引count  当前这次迭代从 1 开始的迭代计数first 用来 ...

  6. winform程序自动升级

    可参考下面这个链接,描述挺详细的,下次用的时候试试,感谢牛逼的作者. http://www.fishlee.net/soft/simple_autoupdater/

  7. js的一些冷门的用法

    1.delete 2.void 0 3.>>> 4.>>0 字符串转为数字 5.[] == ![] 6.

  8. 【JavaEE企业应用实战学习记录】servlet3.0上传文件

    <%-- Created by IntelliJ IDEA. User: Administrator Date: 2016/10/6 Time: 14:20 To change this tem ...

  9. oracle从游标批量提取数据

    来源于:http://blog.csdn.net/ceclar123/article/details/7974973 传统的fetch into一次只能取得一条数据,使用fetch bulk coll ...

  10. Qt自定义窗体,边框,圆角窗体

    MainWindow::MainWindow(QWidget*parent): QMainWindow(parent), ui(new Ui::MainWindow) { setAttribute(Q ...