BestCoder Round #41 -- (A, B)

Source: Internet
Author: User

BestCoder Round #41 -- (A, B)

 

Question transfer: BestCoder Round #41

 

 

A. ZCC loves straight flush

 

Train of Thought: simple question, but I didn't see the question at the beginning. wa had done it several times before I found that the input was not continuous. That is to say, each card of the same color can be placed in one piece, I don't need to care about the input order. I feel it should be clear about the question here.

 

AC code ):

 

#include 
 
  #include 
  
   #include 
   
    #include #include 
    
     #include 
     
      #include 
      
       #include 
       
        #include
        #include 
         
          #include 
          
           #include 
           
            #define LL long long#define INF 0x7fffffffusing namespace std;char a[5][5];int fun(int *p, int n) { sort(p, p + n); int ret = 1; if(p[0] != 1) { for(int i = 1; i <= 9; i ++) { int cur = 0; for(int j = 0; j < n; j ++) { if(p[j] <= i + 4 && p[j] >= i) { cur ++; } ret = max(ret, cur); } } } else if(p[0] == 1) { for(int i = 1; i <= 10; i ++) { int cur = 0; for(int j = 0; j < n; j ++) { if(p[j] <= i + 4 && p[j] >= i) { cur ++; } } if(i == 10) cur ++; ret = max(ret, cur); } } return ret;}int main() { int T; scanf("%d", &T); while(T --) { scanf("%s %s %s %s %s", a[0], a[1], a[2], a[3], a[4]); int cur = 1; int num[5]; memset(num, 0, sizeof(num)); for(int i = 0; i < 5; i ++) { int len = strlen(a[i]); for(int j = 1; j < len; j ++) { num[i] = num[i] * 10 + a[i][j] - '0'; } } /*for(int i = 0; i < 5; i ++) { cout << num[i] << " "; } cout << endl;*/ int A[5], B[5], C[5], D[5]; int an = 0, bn = 0, cn = 0, dn = 0; for(int i = 0; i < 5; i++) { if(a[i][0] == 'A') A[an ++] = num[i]; else if(a[i][0] == 'B') B[bn ++] = num[i]; else if(a[i][0] == 'C') C[cn ++] = num[i]; else if(a[i][0] == 'D') D[dn ++] = num[i]; } int ans = 1; ans = max(ans, fun(A, an)); ans = max(ans, fun(B, bn)); ans = max(ans, fun(C, cn)); ans = max(ans, fun(D, dn)); printf("%d\n", 5 - ans); } return 0;}
           
          
         
       
      
     
    
   
  
 


 

 

 

 

B. ZCC loves strings

 

Train of Thought: Find the rule, simple game, but there are many pitfalls, there are a total of Cn in 2, and then Miss G wins an odd and even number together, when selecting the same string, determine whether the ans is 0 and then obtain a gcd. Remember to use longlong to blow up the int.

 

AC code:

 

#include 
 
  #include 
  
   #include 
   
    #include #include 
    
     #include 
     
      #include 
      
       #include 
       
        #include 
        
         #include
         #include 
          
           #include 
           
            #include 
            
             #define LL long long#define INF 0x7fffffffusing namespace std;int a[200005];LL gcd(LL a, LL b) { return b == 0 ? a : gcd(b, a % b);}int main() { ios::sync_with_stdio(false); int T, n; scanf("%d", &T); while(T --) { scanf("%d", &n); string tmp; LL ji = 0, ou = 0; map
             
               mmp; LL jia = 0; for(int i = 0; i < n; i ++) { cin >> tmp; if(mmp.find(tmp) != mmp.end()) { jia += mmp[tmp]; mmp[tmp] ++; } else mmp[tmp] = 1; a[i] = tmp.length(); if(a[i] & 1) ji ++; else ou ++; } LL ans = ji * ou; LL sum = n * (n - 1) / 2; ans += jia; if(ans == 0) { printf("0/1\n"); continue; } LL gg = gcd(ans, sum); ans /= gg; sum /= gg; cout << ans << '/' << sum << endl; } return 0;}
             
            
           
          
        
       
      
     
    
   
  
 


 

 

 

 

 

Okay, this is a little better game I 've been playing with algorithms for more than half a year. Although I 've been playing a game for the last few minutes, I'm still very excited about the hack process. It's very touching, BC purple name, although the quality is not too high, but very excited, quietly waiting for my CF purple name, first posted an image to commemorate

 

 

 

 

 

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.