Piotr's Ants

Porsition:Uva 10881 白书P9

中文改编题:【T^T】【FJUT】第二届新生赛真S题地震了

"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 horizontal pole L cm long. Each ant is facing either left or right and walks at a constant speed of 1 cm/s. When two ants bump into each other, they both turn around (instantaneously) and start walking in opposite directions. Piotr knows where each of the ants starts and which direction it is facing and 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. N test 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 (measured in 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 the n ants in the same format and order as in the input. If two or more ants are at the same location, print ‘Turning’ instead of ‘L’ or ‘R’ for their 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

2

10 1 4

1 R

5 R

3 L

10 R

10 2 3

4 R

5 L

8 R

Sample Output

Case #1:

2 Turning

6 R

2 Turning

Fell off

Case #2:

3 L

6 R

10 R

Solution

脑洞大开,两只蚂蚁相撞返回相当于穿过?但保证每只蚂蚁初始的顺序.所以每只蚂蚁直接向左向右走,实际上它会穿过很多只蚂蚁,每穿过一次就变一次身,但他们的先后顺序是保证的,就是不会真正穿过去,只是用对面那只蚂蚁代替自己,所以只要记录蚂蚁排列顺序对应在原序列第几个即可。

福利数据

戳这~

Code

// <ants.cpp> - Mon Oct 10 16:18:55 2016
// This file is made by YJinpeng,created by XuYike's black technology automatically.
// Copyright (C) 2016 ChangJun High School, Inc.
// I don't know what this program is. #include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#define MOD 1000000007
#define INF 1e9
using namespace std;
typedef long long LL;
const int MAXN=10010;
inline int gi() {
register int w=0,q=0;register char ch=getchar();
while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
if(ch=='-')q=1,ch=getchar();
while(ch>='0'&&ch<='9')w=w*10+ch-'0',ch=getchar();
return q?-w:w;
}
struct node{
int p,id;char c;
bool operator<(node b)const{return p<b.p;}
}a[MAXN];int d[MAXN];
int main()
{
freopen("ants.in","r",stdin);
freopen("ants.out","w",stdout);
int T=gi();
for(int o=1;o<=T;o++){
printf("Case #%d:\n",o);
int l=gi(),t=gi(),n=gi();
for(int i=1;i<=n;i++)scanf("%d %c",&a[i].p,&a[i].c),a[i].id=i;
sort(a+1,a+1+n);
for(int i=1;i<=n;i++)
d[a[i].id]=i,a[i].p-=(a[i].c=='L'?1:-1)*t;
sort(a+1,a+1+n);
for(int i=1,x;x=d[i],i<=n;i++)
if((a[x].p==a[x-1].p&&x-1)||(x+1<=l&&a[x].p==a[x+1].p))printf("%d Turning\n",a[x].p);
else if(a[x].p>=0&&a[x].p<=l)printf("%d %c\n",a[x].p,a[x].c);
else printf("Fell off\n");printf("\n");
}
return 0;
}

  

最新文章

  1. [转]Installing SharePoint 2013 on Windows Server 2012 R2
  2. Hadoop2.6.0的FileInputFormat的任务切分原理分析(即如何控制FileInputFormat的map任务数量)
  3. Linux常用命令03
  4. 玩转WIN7的MKLINK
  5. [SmartFoxServer概述]SFS2X协议
  6. oracle查看所有表的数据量
  7. wordpress模块无法拖拽/显示选项点击无反应
  8. iOS开发网络编程之断点续传-NSURLConnection
  9. 李洪强iOS开发Swift篇---12_NSThread线程相关简单说明
  10. [Javascript] String method: endsWith() &amp;&amp; startsWith()
  11. js select 实现左右传值.html
  12. jsp页面中定时的方法
  13. 微信php接入设计案列
  14. 一个提供jsp免费空间的站点
  15. EF操作扩展之async
  16. ceph在品高云中的实践
  17. Ajax的请求方式几传参的区别
  18. 模拟器配置使用Fildder进行抓包,包含Https+证书
  19. vue2.0项目实战(4)生命周期和钩子函数详解
  20. [Full-stack] 异步即时通信 - Async

热门文章

  1. 安装Vmware Tools出现错误
  2. PHPExcel读取表格内容
  3. Jquery validate自定义验证
  4. Spring Boot 2 (三):Spring Boot 开源软件都有哪些?
  5. Qt笔记——连接第三方库&amp;用libZPlay库获取音频文件的艺术家、专辑等信息
  6. Android BGABadgeView:新消息/未接来电/未读消息/新通知圆球红点提示(1)
  7. MySQL workbench8.0 CE基本用法(创建数据库、创建表、创建用户、设置用户权限、创建SQL语句脚本)
  8. openjudge7627 鸡蛋的硬度
  9. struct init
  10. codevs——1039 数的划分