uva 10881
View Code
#include<cstdlib> #include<iostream> #include<cstdio> #include<cmath> #include<cstring> #include <algorithm> #include<vector> #include<set> #include<queue> #define LL long long #define inf 0x7fffffff #define E 1e-9 #define N 10009 using namespace std; struct Node { int pos,num; int c; bool operator<(Node x) const { return pos<x.pos; } }; Node node[N]; int n,t,l; int order[N]; char str[3][10]= {"L","Turning","R"}; int main() { #ifndef ONLINE_JUDGE freopen("ex.in","r",stdin); #endif int ncase,tn=0; scanf("%d",&ncase); while(ncase--) { tn++; printf("Case #%d:\n",tn); scanf("%d%d%d",&l,&t,&n); for(int i=0; i<n; i++) { node[i].num=i; char c; scanf("%d %c",&node[i].pos,&c); if(c=='R') node[i].c=1; else node[i].c=-1; } sort(node,node+n); for(int i=0; i<n; i++) { order[node[i].num]=i; } for(int i=0; i<n; i++) node[i].pos+=node[i].c*t; sort(node,node+n); for(int i=1; i<n; i++) if(node[i-1].pos==node[i].pos) { node[i-1].c=0; node[i].c=0; } for(int p=0; p<n; p++) { int i=order[p]; if(node[i].pos<0||node[i].pos>l) { printf("Fell off\n"); continue; } printf("%d %s\n",node[i].pos,str[node[i].c+1]); } printf("\n"); } return 0; }