Topics
Thinking of solving problems
skillful "simulation" Code
#include <cstdio> #include <iostream> #include <string> using namespace std;
const int maxx=101,maxa=4001,x[4]={0,1,0,-1},y[4]={1,0,-1,0}; int N,xx[maxx],yy[maxx],ans,now[maxx],t[maxx];
string S;
int main () {scanf ("%d", &n); cin>>s;
for (int i=1;i<=n;i++) {scanf ("%d%d", &xx[i],&yy[i]); xx[i]*=2;
yy[i]*=2; if (s[i-1]== ' N ') t[i]=0; else if (s[i-1]== ' E ') t[i]=1; else if (s[i-1]== ' s ') t[i]=2;
else if (s[i-1]== ' W ') t[i]=3; } for (int i=1;i<=n;i++) Now[i]=1;//now to record the current state, 1 means that it is not gone, 2 is ready to disappear, 3 means that it has disappeared for (int i=1;i<maxa;i++)//Because you can walk 0.5 steps, Take 2 first, avoid decimals, walk 4000 steps {for (int j=1;j<=n;j++) xx[j]+=x[t[j]],yy[j]+=y[t[j]];//each point moves for (int j=1;j
<n;j++) {if (now[j]==3) continue;
for (int k=j+1;k<=n;k++)//Two-point collision {if (now[k]==3) continue; if (Xx[j]==xx[k]&&yy[j]==yy[k]) {now[j]=now[k]=2;}
If the direct record is 3, then multiple points collide together, you cannot resolve the}} for (int j=1;j<=n;j++) if (now[j]==2) now[j]=3; } for (int i=1;i<=n;i++) if (now[i]==1) ans++; Record points that have not disappeared
printf ("%d", ans); }