HDU5090 simulation, hash

Source: Internet
Author: User
ACM fans of the same dregs are widely seeking for friends. the blog will keep updating their questions based on their own timing. I hope you can join us. We also hope that everyone can communicate and make progress together. If you have any questions, share questions, and learn resources, you can work together to become the smartest person in the world.
/* HDU 5090 is a simple simulation question, however, there is a deep hash idea. this is my first hash question. it is also my first paper code, without compilation or running. after so many comments, it is worth remembering., because n is very small and does not exceed 100, you can open an array to record how many times each number appears because I + n * k can only increase, therefore, you only need to check from 1 to n one by one. if the hash [I] of the current check is 0, there is no solution: because it is impossible to change other numbers to the hash [I]> 1 of the current check, the I must be changed to j = n * k + I (n> 0 ), hash [j] = 0 indicates that j has not changed from number I in the input number. if the hash [I] = 1 of the current check is repeated, you only need to determine the flag */# include
 
  
# Include
  
   
# Include
   
    
# Include
    # Include
     
      
# Include
      
        # Include
       
         # Include
        
          # Include
         
           Using namespace std; # define input freopen ("input.txt", "r", stdin); # define output freopen ("output.txt", "w", stdout ); # define For1 (I, a, B) for (I = a; I
          
            B; I --) # define Dec2 (I, a, B) for (I = a; I> = B; I --) # define Sca_d (x) scanf ("% d", & x) # define Sca_s (x) scanf ("% s", x) # define Sca_c (x) scanf ("% c ", & x) # define Sca_f (x) scanf ("% f", & x) # define Sca_lf (x) scanf ("% lf", & x) # define Fill (x, a) memset (x, a, sizeof (x) # define MAXN 1110 template
           
             T gcd (T a, T B) {return B = 0? A: gcd (B, a % B);} template
            
              T lcm (T a, T B) {return a/gcd (a, B) * B;} int main () {int hash [MAXN]; int t, n, k, I, j, m, flag; cin> t; while (t --) {cin> n> k; Fill (hash, 0); For2 (I, 1, n) Sca_d (m), hash [m] ++; flag = 1; For2 (I, 1, n) if (! Hash [I]) {flag = 0; break;} else if (hash [I] = 1) continue; else {for (j = I + k; j <= n; j + = k) if (hash [I]> 1 & hash [j] = 0) {hash [j] = 1; hash [I] -- ;}}if (flag) cout <"Jerry \ n"; else cout <"Tom \ n" ;}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.