Scu oj 4445 Right turn 2015 Sichuan games J questions (simulation questions)

Source: Internet
Author: User

Scu oj 4445 Right turn 2015 Sichuan games J questions (simulation questions)

General Simulation questions. Create a set for each x that appears, as for y. Then, you can find the point to go to. You need to record the status and determine whether there is a wireless loop. If there is a wireless loop, it will be tle.

 

#include
 
  #include
  
   #include
   
    #include
    
     #include
     
      #include
      
       #include
       #include#include
        
         #include
         
          using namespace std;const int mmax = 500010;const int inf=0x3fffffff;struct node{ int x,y; void read() { scanf("%d %d",&x,&y); } node(int x,int y):x(x),y(y) {} node() {} bool operator < (const node &a) const { if(x==a.x) return yqx,qy;set
          
            Sx[2100],Sy[2100];int dir[4][2]={1,0,0,-1,-1,0,0,1};map
           
            q;bool vis[10100][4];bool fuck(int x,int y){ int cnt=0; for(int i=0;i<4;i++) { int tx=x+dir[i][0]; int ty=y+dir[i][1];// if(x==0 && y==0)// {// cout<
            
             ::iterator it; if(fuck(nowx,nowy)) { fg=0; break; } it=Sy[ qy[nowy] ].upper_bound(nowx); if(it!=Sy[ qy[nowy] ].end()) { int tx=*it; tx--; nowx=tx; nowdir++; nowdir%=4; cnt++; } else break; } else if(nowdir==1) { if(!qx.count(nowx)) break; set
             
              ::iterator it; if(fuck(nowx,nowy)) { fg=0; break; } it=Sx[ qx[nowx] ].lower_bound(nowy); if(it!=Sx[ qx[nowx] ].begin()) { it--; int ty=*it; ty++; nowy=ty; nowdir++; nowdir%=4; cnt++; } else break; } else if(nowdir==2) { if(!qy.count(nowy)) break; set
              
               ::iterator it; if(fuck(nowx,nowy)) { fg=0; break; } it=Sy[ qy[nowy] ].lower_bound(nowx); if(it!=Sy[ qy[nowy] ].begin()) { it--; int tx=*it; tx++; nowx=tx; nowdir++; nowdir%=4; cnt++; } else break; } else if(nowdir==3) { if(!qx.count(nowx)) break; set
               
                ::iterator it; if(fuck(nowx,nowy)) { fg=0; break; } it=Sx[ qx[nowx] ].upper_bound(nowy); if(it!=Sx[ qx[nowx] ].end()) { int ty=*it; ty--; nowy=ty; nowdir++; nowdir%=4; cnt++; } else break; } } if(!fg) puts("-1"); else printf("%d\n",cnt); } return 0;}
               
              
             
            
           
          
         
        
      
     
    
   
  
 


 

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.