2012 South China Sea Junior race ant

Source: Internet
Author: User
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); }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.