#include <iostream> #include <cstdio> #include <algorithm> using namespace std; const int maxn=10000+10; struct Ant { int id;int pos;int dire;// -1 left 0 turn center 1 right bool operator<(const Ant & p)const { return pos<p.pos; } }before[maxn],after[maxn]; intmain() { int t;scanf("%d",&t);int k=0; while(t--){ int L,T,n; scanf("%d %d %d",&L,&T,&n); for(int i=0;i<n;i++){ int a; char ch; scanf("%d %c",&a,&ch); int b; if(ch=='L') b=-1;else b=1; before[i].id=i; before[i].pos=a; before[i].dire=b; after[i].id=0; after[i].pos=a+T*b; after[i].dire=b; // before[i]=Ant{i,a,b}; // after[i]=Ant{0,a+b*T,b}; // struct Ant before[i]={i,a,b}; // struct Ant after[i]={0,a+b*T,b}; } int order[maxn]; sort(before,before+n); for(int i=0;i<n;i++) order[before[i].id]=i;//This place is difficult to understand because the order of input and output should be the same, but we need to sort the code when we type, so we need to save the order //So we introduced order to record the current i-th is the original input (after[i].id). And introduced order. sort(after,after+n); for(int i=0;i<n-1;i++){ if(after[i].pos==after[i+1].pos) {after[i].dire=0;after[i+1].dire=0;} }//Judge the following direction printf("Case #%d:\n",++k); for(int i=0;i<n;i++){ int a=order[i];//The current order[i] is the original a, the original i is the current a if(after[a].pos<0||after[a].pos>L) printf("Fell off\n"); else if(after[a].dire==-1) printf("%d L\n",after[a].pos); else if(after[a].dire==0) printf("%d Turning\n",after[a].pos); else if(after[a].dire==1) printf("%d R\n",after[a].pos); } printf("\n"); } } Note: If you start saving from i=1, you must pay attention to changing the judgment conditions accordingly, otherwise you can only keep wa, I am a living example
uva 10881 Ant
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=325192397&siteId=291194637
Recommended
Ranking