Uva10881 Piotr's Ants
蚂蚁相撞会各自回头。←可以等效成对穿而过,这样移动距离就很好算了。
末状态蚂蚁的顺序和初状态其实是相同的。
那么剩下的就是记录每只蚂蚁的标号,模拟即可。
/*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的更多相关文章
- Uva---10881 Piotr's Ants(蚂蚁)
Problem DPiotr's AntsTime Limit: 2 seconds "One thing is for certain: there is no stopping them ...
- 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 ...
- 10881 - Piotr's Ants(排序)
题目链接:10881 - Piotr's Ants 题目大意:在一个长为L的木棒上有n只蚂蚁,给出蚂蚁的初始位置以及方向,问说移动T秒后各个蚂蚁的位置以及状态,如果两只蚂蚁在移动的过程中相撞,则会同时 ...
- 【巧妙的模拟】【UVA 10881】 - Piotr's Ants/Piotr的蚂蚁
</pre></center><center style="font-family: Simsun;font-size:14px;"><s ...
- 10881 - Piotr's Ants
Problem D Piotr's Ants Time Limit: 2 seconds "One thing is for certain: there is no stopping th ...
- UVA.10881 Piotr's Ants (思维题)
UVA.10881 Piotr's Ants (思维题) 题意分析 有一根长度为L cm的木棍,上有n只蚂蚁,蚂蚁要么向左爬,要么向右,速度均为1cm/s,若2只蚂蚁相撞,则蚂蚁同时调头.求解第T秒时 ...
- 【UVa 10881】Piotr's Ants
Piotr's Ants Porsition:Uva 10881 白书P9 中文改编题:[T^T][FJUT]第二届新生赛真S题地震了 "One thing is for certain: ...
- 思维题 UVA 10881 Piotr's Ants
题目传送门 /* 题意:在坐标轴上一群蚂蚁向左或向右爬,问经过ts后,蚂蚁的位置和状态 思维题:本题的关键1:蚂蚁相撞看作是对穿过去,那么只要判断谁是谁就可以了 关键2:蚂蚁的相对位置不变 关键3:o ...
- cogs 1456. [UVa 10881,Piotr's Ants]蚂蚁
1456. [UVa 10881,Piotr's Ants]蚂蚁 ★ 输入文件:Ants.in 输出文件:Ants.out 简单对比时间限制:1 s 内存限制:128 MB [题目描述 ...
随机推荐
- 转:小白编译openwrt固件教程
原文地址 编译openwrt固件并没有想象的那么复杂,我也是个小白,以下内容是我将网络上的编译教程稍微进行了一下整合.因为我发现很多编译教程没有说明如何更改flash相关配置. 安装ubuntu, ...
- java 中的异步回调
异步回调,本来在c#中是一件极为简单和优雅的事情,想不到在java的世界里,却如此烦琐,先看下类图: 先定义了一个CallBackTask,做为外层的面子工程,其主要工作为start 开始一个异步操作 ...
- Openwrt iptables分析
这里将载有Openwrt的WR841N的路由表dump出来分析一下. 这个是dump出iptables的命令 root@OpenWrt:/etc/config# iptables-save 这里分为4 ...
- 用canvas画“哆啦A梦”时钟
前言:今天看完了Js书的canvas画布那张,好开心~又是心爱的canvas~欧耶~ 之前看到有人建议我画蓝胖子,对哦,我怎么把童年最喜欢的蓝胖子忘了,为了表达我对蓝胖子的歉意,所以今天画了会动的he ...
- HTML5+JS 《五子飞》游戏实现(六)鼠标响应与多重选择
上一章我们提到了如果有多条线上的棋子可以被吃掉,那么游戏需要提示用户,让用户选择吃哪条线上的.另外因为是网页游戏,所以一定要实现鼠标单击棋子可以进行操作. 当鼠标移动棋子上面后,切换鼠标指针为手形,移 ...
- 阅读DNA-2014年读书
- WEB API 中HTTP的get、post、put,delete 请求方式
一.WEB API 中HTTP 请求方式的四个主要方法 (GET, PUT, POST, DELETE), 按照下列方式映射为 CURD 操作: 1.POST 用于新建资源,服务端在指定的URI 上创 ...
- dig 常用的域名查询工具
dig 命令是常用的域名查询工具,可以用来测试域名系统工作是否正常. 语法: dig (选项) (参数) 选项: @<服务器地址>: 指定进行域名解析的域名服务器: -b: 当主机具有多个 ...
- px和em和rem的区别
一.px特点: 1. IE无法调整那些使用px作为单位的字体大小: 2. 国外的大部分网站能够调整的原因在于其使用了em或rem作为字体单位: 3. Firefox能够调整px和em,rem,但是96 ...
- Java开发利器Myeclipse全面详解
Java开发利器Myeclipse全面详解: Ctrl+1:修改代码错误 Alt+Shift+S:Source命令 Ctrl+7:单行注释 Ctrl+Shift+/ :多行注释 Ctrl+I :缩进( ...