博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
UVA10881 Piotr's Ants
阅读量:7092 次
发布时间:2019-06-28

本文共 2002 字,大约阅读时间需要 6 分钟。

Piotr's Ants
Time Limit: 2 seconds

 

 

"One thing is for certain: there is no stopping them;
the ants will soon be here. And I, for one, welcome our
new insect overlords."

Kent Brockman

 

 

 

Piotr likes playing with ants. He has n of them on a horizontalpole L cm long. Each ant is facing either left or right and walksat a constant speed of 1 cm/s. When two ants bump into each other, theyboth turn around (instantaneously) and start walking in opposite directions.Piotr knows where each of the ants starts and which direction it is facingand wants to calculate where the ants will end up T seconds from now.

Input

The first line of input gives the number of cases, NNtest cases follow. Each one starts with a line containing 3 integers:L , T and n (0 <= n <= 10000).The next n lines give the locations of the n ants (measuredin cm from the left end of the pole) and the direction they are facing(L or R).

Output

For each test case, output one line containing "Case #x:"followed by n lines describing the locations and directions of then ants in the same format and order as in the input. If two or moreants are at the same location, print "Turning" instead of "L" or "R" fortheir direction. If an ant falls off the pole before T seconds,print "Fell off" for that ant. Print an empty line after each test case.

Sample Input Sample Output
210 1 41 R5 R3 L10 R10 2 34 R5 L8 R
Case #1:2 Turning6 R2 TurningFell offCase #2:3 L6 R10 R

 

 

题解:

这个题目我们可以发现每次相碰,他们的相对位置都不会发生改变,所以我们可以想如果两只蚂蚁相互碰撞,可以看成他们相互穿过去了,只是编号交换了一下,所以们对每只蚂蚁都这样移动跑一遍,从小到大排序,因为相对不位置发生改变,所以我们只要记一下一开始的相对位置然后直接选取就可以了。

 

代码:

#include
#include
#include
#include
#include
const int MAXN=200010;using namespace std;struct people{ int id,place,to;}a[MAXN];struct query{ int id,ren,move;}q[MAXN];int rak[MAXN],wei[MAXN],ans[MAXN];int n,h,flag=1; bool cmp(people x,people y){
return x.place

 

转载于:https://www.cnblogs.com/renjianshige/p/7302485.html

你可能感兴趣的文章
得到当前日期前一天的零时零分零秒及当前日的零时零分零秒
查看>>
内存堆与栈的区别
查看>>
NHibernate初学者指南(12):日志
查看>>
30 个设计新颖的网站风格展示
查看>>
概念——统一资源定位符(Uniform / Universal Resource Locator,URL)
查看>>
Apache HttpComponents 获取Cookie
查看>>
彻底理解jdbc为什么用反射创建驱动程序对象
查看>>
Oracle内存管理(之五)
查看>>
[nio]dawn的基本概念
查看>>
【数据库摘要】6_Sql_Inner_Join
查看>>
交叉熵代价函数(损失函数)及其求导推导
查看>>
Android UI开源框架
查看>>
Java 构造时成员初始化的陷阱
查看>>
CentOS7.1 Liberty云平台之环境准备(2)
查看>>
js正则表达式test方法、exec方法与字符串search方法区别
查看>>
4.终端
查看>>
优秀的 Spring Cloud 开源软件
查看>>
mysql数据库的简单语句的介绍(1)
查看>>
HDU 2829 Lawrence (斜率DP)
查看>>
visual studio 2012 update3
查看>>