UVA 10881 Piotr's Ants
来源:互联网 发布:pdf.js 获取当前页数 编辑:程序博客网 时间:2024/05/17 03:05
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#include <vector>#include <queue>#include <set>#include <map>#include <string>#include <cmath>#include <climits>#include <cstdlib>#include <ctime>using namespace std;//ios::sync_with_stdio(false);struct node{int x,c,i;};node a[10005];node next[100005];int cmp(node a,node b){return a.x < b.x;}int cmp1(node a,node b){return a.i < b.i;}int main(){ios::sync_with_stdio(false);int q;cin >> q;for(int h = 1; h <= q ;h++){int l,t,n;cin >> l >> t >> n;for(int i = 0; i < n ;i++){char ch;cin >> a[i].x >> ch;a[i].c = (ch == 'R') ? 1: -1;next[i].x = a[i].x + t * a[i].c;next[i].c = a[i].c;a[i].i = i;}sort(a,a+n,cmp);sort(next,next+n,cmp);for(int i = 0 ; i < n;i++){next[i].i = a[i].i;if(i < n-1 && next[i].x == next[i+1].x){next[i].c = 0;next[i+1].c = 0;}}sort(next,next+n,cmp1);printf("Case #%d:\n",h);for(int i = 0; i < n;i++){if(next[i].x > l||next[i].x < 0){printf("Fell off\n");}else{printf("%d ",next[i].x);if(next[i].c == 0 ){printf("Turning\n");}else if(next[i].c == 1){printf("R\n");}else{printf("L\n");}}}printf("\n");}return 0;}注意到每一只蚂蚁碰到之后都转向,就相当于两只蚂蚁没有转头一样仍然按照原来的方向前进。如果按照这种方法求的话那么t时间之后在什么位置有蚂蚁就可以求出来了。
但那时这时候每只蚂蚁的方向确定了,但是这只蚂蚁是原来的什么位置的蚂蚁却不知道。通过观察可以知道。蚂蚁之间的相对位置从来没有改变,也就是说每只蚂蚁旁边的蚂蚁是哪只蚂蚁没有改变,如果把原先的蚂蚁按照他们在绳子上的位置排序,那么t时间之后的蚂蚁的位置的排序也是对应的蚂蚁就是同一只蚂蚁。
Description
Piotr's Ants
Time Limit: 2 seconds
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
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 beforeT seconds, print "Fell off" for that ant. Print an empty line after each test case.
210 1 41 R5 R3 L10 R10 2 34 R5 L8 R
Case #1:2 Turning6 R2 TurningFell offCase #2:3 L6 R10 R
- UVa - 10881 - Piotr's Ants
- uva 10881 - Piotr's Ants
- Uva-10881-Piotr's Ants
- uva 10881 - Piotr's Ants
- UVa 10881 Piotr's Ants
- UVA 10881 Piotr's Ants
- Piotr's ants UVA 10881
- UVa 10881 - Piotr's Ants
- UVa 10881 Piotr's Ants
- UVA - 10881 Piotr's Ants
- uva 10881 Piotr's Ants
- UVA - 10881 Piotr's Ants
- UVa 10881 - Piotr's Ants
- UVa 10881 - Piotr's Ants
- Uva 10881 - Piotr's Ants
- UVA 10881 Piotr's Ants
- UVA 10881 - Piotr's Ants
- 【UVA】10881-Piotr's Ants
- spring 事务管理文档意译(2/5)
- Android中launcherMode="singleTask"详解<解决home键返回不能出现原界面问题>
- JavaScript中,关于new的那些事
- json和ajax基础运用
- BNUOJ44586(栈模拟)
- UVA 10881 Piotr's Ants
- Ubuntu中compiz 安装与设置
- loadermanager使用解析之个人见解
- 电脑任务管理器里的进程
- Reverse Words in a String
- [2014-12-28]Java笔记_Junit 3.8
- SQLServer 中dm_os_ring_buffers(ring_buffer_connectivity)读取XML
- FragmentpagerAdapter中的getItem方法,在第二次进入承载viewPager的Fragment时不会被调用原因
- 手机发送验证码—.net代码