10881 - Piotr's Ants
Problem D
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, N. Ntest 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 |
2 |
Case #1: |
#include<iostream>
#include<algorithm>
using namespace std;
struct data{int x;char u;int o;}p[10005];
int temp(void const *p,void const *q)
{
return (*(data *)p).x-(*(data *)q).x;
} int main()
{
int N,l,t,n,count=1;
cin>>N;
while(N--)
{
int order[10005]={0};
cin>>l>>t>>n;
for(int i=0;i<n;i++)
{
cin>>p[i].x>>p[i].u;
p[i].o=i;
}
qsort(p,n,sizeof(p[0]),temp);
for(int i=0;i<n;i++)
order[p[i].o]=i;
for(int i=0;i<n;i++)
if(p[i].u=='L') p[i].x-=t;
else p[i].x+=t;
qsort(p,n,sizeof(p[0]),temp);
for(int i=0;i<n-1;i++)
if(p[i].x==p[i+1].x)
{
p[i].u='T';
p[i+1].u='T';
}
cout<<"Case #"<<count++<<":"<<endl;
for(int i=0;i<n;i++)
{
int a=order[i];
if(p[a].x<0||p[a].x>l) cout<<"Fell off"<<endl;
else
{
cout<<p[a].x<<" ";
if(p[a].u=='T') cout<<"Turning"<<endl;
else cout<<p[a].u<<endl;
}
}
cout<<endl;
}
return 0;
}
10881 - Piotr's Ants的更多相关文章
- 10881 - Piotr's Ants(排序)
题目链接:10881 - Piotr's Ants 题目大意:在一个长为L的木棒上有n只蚂蚁,给出蚂蚁的初始位置以及方向,问说移动T秒后各个蚂蚁的位置以及状态,如果两只蚂蚁在移动的过程中相撞,则会同时 ...
- 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 蚂蚁
一根长度为 L 厘米的木棍上有 n 只蚂蚁,每只蚂蚁要么朝左爬,要么朝右爬,速度为 1 厘米/秒.当两只蚂蚁相撞时,二者同时调头(掉头用的时间忽略不计).给出每只蚂蚁的初始位置和朝向,计算 T 秒之后 ...
- uva 10881 - Piotr's Ants
这个题的突破点就在于蚂蚁不能够穿过对方,故相对位置不变: 另外,又可以把蚂蚁看成运动方向不变: 代码: #include<cstdio> #include<algorithm> ...
随机推荐
- Storm 配置图文解析
Storm 配置图文解析 參考阅读:http://www.xiaofateng.com/? p=959 ============================== | sample-topology ...
- sql2008R2sp1局域网镜像环境实操(无见证服务器)
环境介绍: 我的电脑:sql2008r2sp1_32 129.186.110.37 OS win2003 SP2 Enterprise 做主体服务器, 暂叫ServerA 服务器: sq ...
- Web端的Tab控件在切换Tab时Load数据出错的处理
我们在应用Web端的Tab控件时,不管是Jquery easyui的还是Ext的Tab控件都会遇到一个问题,在Tab1正在加载数据的时候我们切换到Tab2,再切换回来,Load数据的控件就会出错,出错 ...
- 【转载】CentOS日志系统组成详解
日志系统有三部分组成:一.使用什么工具记录系统产生的日志信息? syslog服务脚本管理的两个进程: syslogd.klogd 来记录系统产生的日志信息: klogd 进 ...
- VS2008查看dll导出函数
打开Visual Studio 2008 命令提示,使用命令 [plain] view plaincopyprint? dumpbin /exports simple.dll 即可查看
- SmartGit 试用过期
smartgit是见过的最好用的git客户端, 要解决其试用版过期的问题,如下: 1.定位到文件夹 Windows: %APPDATA%\syntevo\SmartGit\OS X: ~/Librar ...
- lsh341999的资源
懒得下载了,仔细研究: http://download.csdn.net/user/lsh341999/uploads/2
- 将某个MySQL库中的UTF8字符列都转成GBK格式
DELIMITER $$ DROP PROCEDURE IF EXISTS `dba`.`Proc_ChangeCharacter2GBK`$$ CREATE DEFINER=`root`@`%` P ...
- sqlserver bak还原
一.查看: restore filelistonly from disk='F:\Db\A_backup.bak' 二.还原:RESTORE DATABASE AFROM DISK = 'F:\Db\ ...
- Delphi中MethodAddress汇编代码的解析
class function TObject.MethodAddress(const Name: ShortString): Pointer;asm { -> EAX ...