Poj 1781 In Danger (Joseph's ring, finding Rules)

Source: Internet
Author: User

Poj 1781 In Danger (Joseph's ring, finding Rules)

 

Joseph Ring template, each time count to 2 people out of the ring.

However, we can directly find that TLE and n are too large.

The answer is related to n. When n is the power of 2, the answer is 1. If n is not the power of 2, it is a multiple of 2 that is different from the power less than 2.

 

 

#include 
 
  #include 
  
   #include
   #include 
    
     #include 
     
      #include 
      
       #include 
       
        #include 
        
         #include 
         
          #include 
          
           #include 
           
            #include 
            
             #include #define LL long long#define _LL __int64#define eps 1e-12#define PI acos(-1.0)#define C 240#define S 20using namespace std;int p[30];int main(){for(int i = 0; i <= 27; i++){p[i] = 1<
             
              = n)break;if(p[i] == n)printf(1);elseprintf(%d,(n-p[i-1])*2+1); } 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.