uva 10881 - Piotr's Ants
这个题的突破点就在于蚂蚁不能够穿过对方,故相对位置不变;
另外,又可以把蚂蚁看成运动方向不变;
代码:
#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的更多相关文章
- UVA.10881 Piotr's Ants (思维题)
UVA.10881 Piotr's Ants (思维题) 题意分析 有一根长度为L cm的木棍,上有n只蚂蚁,蚂蚁要么向左爬,要么向右,速度均为1cm/s,若2只蚂蚁相撞,则蚂蚁同时调头.求解第T秒时 ...
- 思维题 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 [题目描述 ...
- POJ 1852 Ants || UVA 10881 - Piotr's Ants 经典的蚂蚁问题
两题很有趣挺经典的蚂蚁问题. 1.n只蚂蚁以1cm/s的速度在长为L的竿上爬行,当蚂蚁爬到竿子的端点就会掉落.当两只蚂蚁相撞时,只能各自反向爬回去.对于每只蚂蚁,给出距离左端的距离xi,但不知道它的朝 ...
- 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 ...
- [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 ...
- UVA 10881 - Piotr's Ants【模拟+思维】
题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- uva 10881 Piotr's Ants 解题报告
题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=20&pa ...
- Uva 10881 Piotr’s Ants 蚂蚁
一根长度为 L 厘米的木棍上有 n 只蚂蚁,每只蚂蚁要么朝左爬,要么朝右爬,速度为 1 厘米/秒.当两只蚂蚁相撞时,二者同时调头(掉头用的时间忽略不计).给出每只蚂蚁的初始位置和朝向,计算 T 秒之后 ...
随机推荐
- php 5.3+ 连接mssql
php5.3+里已经没有mssql的dll扩展了,需要使用SQL Server Driver for PHP 这里有两个版本有两个版本支持不同的php版本. 1.SQL Server Driver f ...
- SQL 收缩数据库文件大小
USE WebExam; GO ALTER DATABASE WebExam SET RECOVERY SIMPLE; GO -- 收缩文件到 1 MB. ); GO ALTER DATABASE W ...
- Maven 私服的使用实战
本日志主要是介绍下面的配置 1. 将内部构件部署到私服 在工程的pom文件中添加下面配置 <distributionManagement> <repository> <i ...
- Atom 插件安装
“webstom” 目前还没免费版的 不过类似的倒是有个! 首先想到的一句话是:还在为webstom不是正版而发愁吗? 其实很小的时候我们的世界是非黑即白的,但慢慢长大后,发现其实还有灰色的存在! 工 ...
- C++实现RTMP协议发送H.264编码及AAC编码的音视频
http://www.cnblogs.com/haibindev/archive/2011/12/29/2305712.html C++实现RTMP协议发送H.264编码及AAC编码的音视频 RTMP ...
- 周末充电之WPF(三 ) .后台动态生成控件
布局 -连连看: 代码: private void Window_Loaded_1(object sender, RoutedEventArgs e) { //动态创建行 ; i < ; i++ ...
- transfrom属性
transfrom可以实现一些形变.常见的有平移.缩放和旋转三种.使用起来很简单: //横纵放大1.3倍 self.imageButton.transform=CGAffineTransformSca ...
- C#操作redis代码汇总
马上要用redis来改造现有的o2o项目了,在linux下部署了个redis,顺便研究了下代码操作,分享下代码 using System; using System.Collections.Gener ...
- UVA 11995 I Can Guess the Data Structure!(ADT)
I Can Guess the Data Structure! There is a bag-like data structure, supporting two operations: 1 x T ...
- Headfirst设计模式的C++实现——装饰者模式(Decorater)
Beverage.h #ifndef BEVERAGE_H_INCLUDED #define BEVERAGE_H_INCLUDED #include <string> class Bev ...