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;
}

  

【UVa 10881】Piotr's Ants的更多相关文章

  1. 【巧妙的模拟】【UVA 10881】 - Piotr's Ants/Piotr的蚂蚁

    </pre></center><center style="font-family: Simsun;font-size:14px;"><s ...

  2. 【巧妙算法系列】【Uva 11464】 - Even Parity 偶数矩阵

    偶数矩阵(Even Parity, UVa 11464) 给你一个n×n的01矩阵(每个元素非0即1),你的任务是把尽量少的0变成1,使得每个元素的上.下.左.右的元素(如果存在的话)之和均为偶数.比 ...

  3. 【贪心+中位数】【UVa 11300】 分金币

    (解方程建模+中位数求最短累积位移) 分金币(Spreading the Wealth, UVa 11300) 圆桌旁坐着n个人,每人有一定数量的金币,金币总数能被n整除.每个人可以给他左右相邻的人一 ...

  4. 【UVa 116】Unidirectional TSP

    [Link]:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_probl ...

  5. 【UVa 1347】Tour

    [Link]:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_probl ...

  6. 【UVA 437】The Tower of Babylon(记忆化搜索写法)

    [题目链接]:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_probl ...

  7. 【uva 1025】A Spy in the Metro

    [题目链接]:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_probl ...

  8. 【Uva 11584】Partitioning by Palindromes

    [Link]:https://cn.vjudge.net/contest/170078#problem/G [Description] 给你若干个只由小写字母组成的字符串; 问你,这个字符串,最少能由 ...

  9. 【Uva 11400】Lighting System Design

    [Link]: [Description] 你要构建一个供电系统; 给你n种灯泡来构建这么一个系统; 每种灯泡有4个参数 1.灯泡的工作电压 2.灯泡的所需的电源的花费(只要买一个电源就能供这种灯泡的 ...

随机推荐

  1. layuiAdmin 项目修改

    layuiAdmin修改 index.js 修改登录url user/login=>publics/login config.js 修改 name 项目名称, tokenName token字段 ...

  2. time | sys | os 模块,递归删除文件,项目分析

    一,复习 ''' 1.跨文件夹导包 - 不用考虑包的情况下直接导入文件夹(包)下的具体模块 2.__name__: py自执行 '__main__' | py被导入执行 '模块名' 3.包:一系列模块 ...

  3. Python中的列表(4)

    1.遍历列表 如果想打印列表中的所有元素,则必须遍历列表. 可以使用for ... in ... 语句来遍历列表中的元素.遍历的意思 words = ['a','b','c','d'] for wor ...

  4. RS232

    RS232的最大的传输速率大约10KBytes/s. 全双工工作方式,异步.数据是8位作为一块来发送的,先发送最低位,最后发送最高位. 在232通信中: Both side of the cable ...

  5. 易维信(EVTrust)支招五大技巧识别钓鱼网站

    网上购物和网上银行凭借其便捷性和通达性,在互联网上日渐流行.在互联网上,你可以随时进行转账汇款或进行交易.据艾瑞咨询发布<2008-2009年中国网上支付行业发展报告>显示:中国互联网支付 ...

  6. 7-9 旅游规划(25 分)(Dijkstra最短路径算法)

    有了一张自驾旅游路线图,你会知道城市间的高速公路长度.以及该公路要收取的过路费.现在需要你写一个程序,帮助前来咨询的游客找一条出发地和目的地之间的最短路径.如果有若干条路径都是最短的,那么需要输出最便 ...

  7. 【裸的并查集】POJ 1611 The Suspects

    http://poj.org/problem?id=1611 [Accepted] #include<iostream> #include<cstdio> #include&l ...

  8. 国王游戏(codevs 1198)

    题目描述 恰逢 H 国国庆,国王邀请 n 位大臣来玩一个有奖游戏.首先,他让每个大臣在左.右手上面分别写下一个整数,国王自己也在左.右手上各写一个整数.然后,让这 n 位大臣排成一排,国王站在队伍的最 ...

  9. POJ——T 2976 Dropping tests

    http://poj.org/problem?id=2976 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 13861   ...

  10. cogs——1001. [WZOI2011 S3] 消息传递

    1001. [WZOI2011 S3] 消息传递 ★★   输入文件:messagew.in   输出文件:messagew.out   简单对比时间限制:1 s   内存限制:128 MB Prob ...