Piotr's Ants UVa 10881
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <queue>
#include <vector>
#define maxn 10005
#define L -1
#define R 1
#define fell 10
#define Turning -10
#define On 0; using namespace std;
struct ants{
int location;
int direction;
int inputorder;
int state;
bool operator < (const ants& a) const{
return location <a.location;
}
}Ant[maxn]; int main(){
//if(freopen("input.txt","r",stdin)== NULL) {printf("Error\n"); exit(0);} int n,l,T;
int N;
cin>>N;
for(int test=;test<=N;test++){
cin>>l>>T>>n;
int a;
char ch;
for(int i=;i<=n;i++){
cin>>a>>ch; if(ch == 'R') Ant[i].direction = R;
else Ant[i].direction = L;
Ant[i].location = a;
Ant[i].inputorder = i;
}
sort(Ant+,Ant+n+);
int order[maxn];
for(int i=;i<=n;i++){
order[Ant[i].inputorder] = i;
} for(int i=;i<=n;i++) Ant[i].location += T * Ant[i].direction; sort(Ant+,Ant+n+); for(int i=;i<=n;i++)
if(Ant[i].location < || Ant[i].location > l)
Ant[i].state = fell;
else if(Ant[i].location == Ant[i+].location && i < n) {
Ant[i].state = Ant [i+].state = Turning;
i++;
}
else
Ant[i].state = On;
printf("Case #%d:\n",test); for(int i=;i<=n;i++){
int j = order[i];
if(Ant[j].state == fell) printf("Fell off\n");
else if(Ant[j].state == Turning){
printf("%d Turning\n",Ant[j].location);
}
else
printf("%d %c\n",Ant[j].location,Ant[j].direction == R ? 'R' : 'L'); }
printf("\n");
}
}
Piotr's Ants UVa 10881的更多相关文章
- POJ 1852 Ants || UVA 10881 - Piotr's Ants 经典的蚂蚁问题
两题很有趣挺经典的蚂蚁问题. 1.n只蚂蚁以1cm/s的速度在长为L的竿上爬行,当蚂蚁爬到竿子的端点就会掉落.当两只蚂蚁相撞时,只能各自反向爬回去.对于每只蚂蚁,给出距离左端的距离xi,但不知道它的朝 ...
- UVA.10881 Piotr's Ants (思维题)
UVA.10881 Piotr's Ants (思维题) 题意分析 有一根长度为L cm的木棍,上有n只蚂蚁,蚂蚁要么向左爬,要么向右,速度均为1cm/s,若2只蚂蚁相撞,则蚂蚁同时调头.求解第T秒时 ...
- 【UVa 10881】Piotr's Ants
Piotr's Ants Porsition:Uva 10881 白书P9 中文改编题:[T^T][FJUT]第二届新生赛真S题地震了 "One thing is for certain: ...
- 思维题 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 [题目描述 ...
- 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 ...
- 【巧妙的模拟】【UVA 10881】 - Piotr's Ants/Piotr的蚂蚁
</pre></center><center style="font-family: Simsun;font-size:14px;"><s ...
- 10881 - Piotr's Ants(排序)
题目链接:10881 - Piotr's Ants 题目大意:在一个长为L的木棒上有n只蚂蚁,给出蚂蚁的初始位置以及方向,问说移动T秒后各个蚂蚁的位置以及状态,如果两只蚂蚁在移动的过程中相撞,则会同时 ...
- 10881 - Piotr's Ants
Problem D Piotr's Ants Time Limit: 2 seconds "One thing is for certain: there is no stopping th ...
随机推荐
- HTTP could not register URL http://+:8000/.... Your process does not have access rights to this namespace
windows 7, Visual Studio 2013 在托管 Windows 服务中承载 WCF 服务时报错: HTTP could not register URL http://+:8000 ...
- 实现HTTP跳转到HTTPS
1 首先在您的网站下新建一个站点,名称随意,在属性中分配TCP端口为80,SSL不分配 然后在属性>主目录下配置 将此资源的内容来自: 改为 重定向到URL 然后重定向到中 输入: HTTP ...
- style currentStyle getComputedStyle的区别和用法
先介绍下层叠样式表的三种形式: 1.内联样式,在html标签中style属性设置. <p style="color:#f90">内联样式</p> 2.嵌入样 ...
- opencv安装及学习资料
第一次装时win7+VS2010+opencv3.0,结果不成功,原因解压出来的没有vc10,可能新版本不在支持vc的旧版本了.所以换了VS2013+opencv3.0,比较经典的安装时VS2010+ ...
- HDU 2295.Radar (DLX重复覆盖)
2分答案+DLX判断可行 不使用的估计函数的可重复覆盖的搜索树将十分庞大 #include <iostream> #include <cstring> #include < ...
- wordpress通过代码禁用IE8, IE9,IE10等IE浏览器兼容视图模式(Compatibility View)
目前wordpress主流主题大多都放弃了对IE6的支持!甚至IE6,IE7,IE8等的兼容模式也不支持!目前特别是国内的双核浏览器大多数使用使用IE内核都是使用的兼容模式!那将是非常糟糕!如何让IE ...
- 数组Api .map()的使用
之前并没有过多的使用过这个Api,在此记录下对其的理解,方便以后多多使用. 首先是对map的说明: var mappedArray = array.map(callback[, thisObject] ...
- Fedora上配置一个安全FTP
现在流行的FTP服务器,比较著名的有WU-FTP(Washington University FTP)和VSFTP(Very Secure FTP 非常安全的FTP)以及Proftp,pureftp等 ...
- centos postfix 邮箱安装记录
---恢复内容开始--- #wget http://nchc.dl.sourceforge.net/project/postfixadmin/postfixadmin/postfixadmin-2.9 ...
- JQuery select控件的相关操作
JQuery获取和设置Select选项方法汇总如下: 获取select 先看看下面代码: $("#select_id").change(function(){//code...}) ...