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 秒之后 ...
随机推荐
- 下载好一个android软件之后,怎样自动提示安装?
最近在做毕设,里面牵涉到版本更新,当有新版本时可以下载新版本,下载完成之后提示安装.那么怎么实现下载完成之后提示安装呢? 直接上代码吧: File mFile = new File(Environme ...
- 关于js原型的面试题
今天遇到关于javascript原型的一道面试题,现分析下: 原题如下: function A(){ } function B(a){ this.a = a; } function C(a){ if( ...
- javascript进击(八)JSON
JSON 是存储和交换文本信息的语法.类似 XML. JSON 比 XML 更小.更快,更易解析. 什么是 JSON ? JSON 指的是 JavaScript 对象表示法(JavaScript Ob ...
- 破解C#的readonly只读字段
破解C#的readonly只读字段 目录 请允许我再唠叨几句const和readonly 修改readonly字段: 计策1:反间计 -- 反射修改 计策2:借刀杀人--调节字段偏移位置的结构体来修改 ...
- Linux screen命令简介
Linux上有的shell脚本运行时候是阻塞的,如果想在屏幕上即能够看到阻塞命令的输出,同时又能够在shell窗口运行其他程序,那么Linux自带的screen命令是非常不错的选择. 1.screen ...
- jqery基础知识
选择器按属性,子元素,表单匹配元素 <!doctype html> <html lang="en"> <head> <meta chars ...
- 【C#】获取本地Cookie的问题
using System; using System.Net; using System.IO; using System.Text; // // TODO: 在此处添加代码以启动应用程序 // st ...
- 那天有个小孩跟我说LINQ(一) 转载
1 LINQ准备(代码下载) 新建项目 linq_Ch1控制台程序,新建一个Entity文件夹 1.1 对象初始化器 在Entity新建一个类Student,代码如下 using S ...
- Google Maps API 调用实例
本实例介绍如何调用Google Maps API,并实现用鼠标标注地图,保存进数据库,以及二次加载显示等. 1.需要新建一个自定义控件(如:Map.ascx),用于显示Google地图: <%@ ...
- [firefly]暗黑源码解析
一.架构 二.各模块详解 1.net 2.gate 3.game 4.db 三.启动 四.举例说明 五.性能测试