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 [题目描述 ...
随机推荐
- CentOS 7.0 Nvidia显卡安装步骤
from: http://blog.sina.com.cn/s/blog_49c0985a0102v3fa.html CentOS 7.0 Nvidia显卡安装步骤: 1 在英伟达官网下载相应驱动 搜 ...
- TinyFrame升级之十:WCF Rest Service注入IOC的心
由于在实际开发中,Silverlight需要调用WebService完成数据的获取,由于之前我们一直采用古老的ASMX方式,生成的代理类不仅难以维护,而且自身没有提供APM模式的调用方式,导致在Sin ...
- python数字图像处理(17):边缘与轮廓
在前面的python数字图像处理(10):图像简单滤波 中,我们已经讲解了很多算子用来检测边缘,其中用得最多的canny算子边缘检测. 本篇我们讲解一些其它方法来检测轮廓. 1.查找轮廓(find_c ...
- python强大的区间处理库interval用法介绍
原文发表在我的博客主页,转载请注明出处 前言 这个库是在阅读别人的源码的时候看到的,觉得十分好用,然而在网上找到的相关资料甚少,所以阅读了源码来做一个简单的用法总结.在网络的路由表中,经常会通过掩码来 ...
- parsing XML document from class path resource
遇到问题:parsing XML document from class path resource [spring/resources] 解决方法:项目properties— source—remo ...
- ContentProvider数据访问详解
ContentProvider数据访问详解 Android官方指出的数据存储方式总共有五种:Shared Preferences.网络存储.文件存储.外储存储.SQLite,这些存储方式一般都只是在一 ...
- PC互联网和移动互联网的本质差别
网一代,我们先称为PC互联网,这大约可以从2010年作为分界,然后就是基于手机,及可穿戴的移动互联网. 在PC时代,软件都很庞大复杂,甚至客端端和网页混合,比如常见的桌面软件,Office及Photo ...
- C#迭代器
迭代器概述 迭代器是可以返回相同类型的值的有序序列的一段代码. 迭代器可用作方法.运算符或 get 访问器的代码体. 迭代器代码使用 yield return 语句依次返回每个元素.yield bre ...
- JavaScript学习笔记-简单的倒计时跳转页面
<!DOCTYPE html> <html lang="en" xmlns="http://www.w3.org/1999/xhtml"> ...
- SEO站点优化学习总结
1.网站收录查询 在搜索引擎里面输入Site:域名 即可. 尾巴——学习SEO可以看看以下几个网站: 卢松松博客[一个草根的博客]:http://lusongsong.com/ 站长之家[里面有站长统 ...