Uva10881 Piotr's Ants
蚂蚁相撞会各自回头。←可以等效成对穿而过,这样移动距离就很好算了。
末状态蚂蚁的顺序和初状态其实是相同的。
那么剩下的就是记录每只蚂蚁的标号,模拟即可。
/*by SilverN*/
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<vector>
using namespace std;
const int mxn=;
struct ants{
int id,p,dir;
int pos;
}a[mxn];
int cmp(const ants x,const ants y){
return x.p<y.p;
}
int cmp2(const ants x,const ants y){
return x.pos<y.pos;
}
int l,t,n;
int mp[mxn];
int main(){
int T,i,j;
scanf("%d",&T);
int cas=;
while(T--){
printf("Case #%d:\n",++cas);
scanf("%d%d%d",&l,&t,&n);
char dr;
for(i=;i<=n;i++){
scanf("%d %c",&a[i].p,&dr);
if(dr=='L') a[i].dir=-;
else a[i].dir=;
}
for(i=;i<=n;i++){
a[i].id=i;
a[i].pos=a[i].p+t*a[i].dir;
}
sort(a+,a+n+,cmp);
for(i=;i<=n;i++){
mp[a[i].id]=i;
}
sort(a+,a+n+,cmp2);
for(i=;i<n;i++){
if(a[i].pos==a[i+].pos){
a[i].dir=a[i+].dir=;
}
}
for(i=;i<=n;i++){
int thi=mp[i];
if(a[thi].pos< || a[thi].pos>l){
printf("Fell off\n");continue;
}
printf("%d ",a[thi].pos);
if(a[thi].dir==-)printf("L\n");
else if(a[thi].dir==)printf("R\n");
else printf("Turning\n");
}
printf("\n");
}
return ;
}
Uva10881 Piotr's Ants的更多相关文章
- Uva---10881 Piotr's Ants(蚂蚁)
Problem DPiotr's AntsTime Limit: 2 seconds "One thing is for certain: there is no stopping them ...
- 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 ...
- 10881 - Piotr's Ants(排序)
题目链接:10881 - Piotr's Ants 题目大意:在一个长为L的木棒上有n只蚂蚁,给出蚂蚁的初始位置以及方向,问说移动T秒后各个蚂蚁的位置以及状态,如果两只蚂蚁在移动的过程中相撞,则会同时 ...
- 【巧妙的模拟】【UVA 10881】 - Piotr's Ants/Piotr的蚂蚁
</pre></center><center style="font-family: Simsun;font-size:14px;"><s ...
- 10881 - Piotr's Ants
Problem D Piotr's Ants Time Limit: 2 seconds "One thing is for certain: there is no stopping th ...
- 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 [题目描述 ...
随机推荐
- Orchard CRM 更新 - 同时支持 Microsoft Dynamics CRM 2011, 2013, 2015, 2016!
本版本支持: 使用Orchard 1.8.1 系统 Dynamics CRM 2015 DLL .Net Framework 4.5.2 演示版本: http://www.orchardcrm.com ...
- 用opencv的traincascade训练检测器
#1,准备正负样本 正样本:可以一张图片上多个sample,也可以一张图片单独成一个sample,准备多个sample.生成描述文件如下所示: 负样本:只要不含正样本,任意图片都可以作为负样本,但是最 ...
- java实战之解析xml
在java中解析xml有现成的包提供方法,常用的有四类:Dom,JDom,Sax以及Dom4j.其中前者是java中自带的,后三者需要大家从开源诸如sourceforge这样的网站下载jar包,然后在 ...
- Theano2.1.15-基础知识之theano如何处理shapre信息
来自:http://deeplearning.net/software/theano/tutorial/shape_info.html How Shape Information is Handled ...
- 自己存档:table 的css
border:0;margin:0;border-collapse:collapse;border-spacing:0;
- SDRAM读写一字(上)
SDRAM读写一字 系统设计 SDRAM指令 指令 常量名 CKE CSn RAS CASn WEn 备注 空操作 NOP 1 0 1 1 1 行激活 ACTIVE 1 0 0 1 1 读操作 ...
- 【BZOJ1003】【ZJOI2006】物流运输
1003: [ZJOI2006]物流运输trans Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 2556 Solved: 1008[Submit] ...
- DataGridView 绑定List集合后实现自定义排序
这里只贴主要代码,dataList是已添加数据的全局变量,绑定数据源 datagridview1.DataSource = dataList,以下是核心代码. 实现点击列表头实现自定义排序 priva ...
- 【Spring3.0系列】---Bean不同配置方式比较 和适用场合
Bean不同配置方式比较1.基于XML配置定义:在XML文件中通过<bean>元素定义Bean,例如<bean class="com.bbt.UserDao"/& ...
- elasticsearch installation guide
UBUNTU 14.04 LTS 安装 elasticseach同步MYSQL表并实现中文搜索 ==================================================== ...