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> ...
随机推荐
- 另外一种方式装win2008r2
装系统有很多方法,但是这种,我很少用. 注意第二个红圈处,是要启动的电话引导盘符.容易选择你的启动U盘,如果是后者,表现出的结果就是引导U盘不能引导,且安装的电脑也会显示ntdl丢失.当然,也可以解决 ...
- #define DEBUG用法
背景: 很多时候我们写代码,想要看看函数或者算法执行的对不对.是否达到了我们想要的效果, 那么,最直接的办法是把函数或者算法所操作数据显示出来看看,这样就需要写一些cout<<直接输出的代 ...
- BZOJ 4143: [AMPPZ2014]The Lawyer( sort )
水题... 排序搞出每天的会议有哪些, 然后再按照会议的开始时间和结束时间排序, 最晚开始的和最早结束的会议不是同一场而且最晚开始的时间>最早结束的会议就有可能方案 -------------- ...
- ORA-19815,ORA-19809 :limit exceeded for recovery files
数据库重新启动的时候,收到了ORA-19815的错误.从错误的提示来看,是由于闪回区的空间被填满导致无法成功启动.这种情形我们通常考虑的是清除归档日志,那就直接在OS层面rm了,真的是这样吗?客官,如 ...
- BitHacks--位操作技巧
---------------------------------------------------------------------------------------------------- ...
- 【PAT】1041. Be Unique (20)
题目链接:http://pat.zju.edu.cn/contests/pat-a-practise/1041 题目描述: Being unique is so important to people ...
- Win7+花生壳6.0+tomcat打做自己的web服务器(搭建自己的网站)(参考)
链接地址:http://blog.csdn.net/zhu_9527/article/details/23344623?utm_source=tuicool&utm_medium=referr ...
- BZOJ 3314: [Usaco2013 Nov]Crowded Cows( 单调队列 )
从左到右扫一遍, 维护一个单调不递减队列. 然后再从右往左重复一遍然后就可以统计答案了. ------------------------------------------------------- ...
- 你真的知道为什么不推荐使用@import?
Difference between @import and link in CSS Use of @import <style type="text/css">@im ...
- Troubleshooting:oVirt-engine
问题:执行./create_db_devel.sh -u postgres创建数据库时出错 描述: [root@localhost dbscripts]# ./create_db_devel.sh - ...