Ultraviolet A -- 1368 (greedy, string simulation)

Source: Internet
Author: User

Ultraviolet A -- 1368 (greedy, string simulation)

 

 

This is a string simulation question with a greedy idea. Given m strings with a length of n, you can find a string with a length of n, the number and minimum number of characters corresponding to the m string.

To minimize the number of characters in the corresponding position, each character in the string takes precedence over the characters with more occurrences at the position. If the number of occurrences is the same, the character with a smaller Lexicographic Order is selected.

Code:

 

# Include
 
  
# Include
  
   
# Include
   
    
# Include
    # Include
     
      
# Include
      
        # Include
       
         # Include
        
          # Include
         
           # Define from (I, a, n) for (int I = a; I
          
            = A; I --) # define EPS 1e-10 # define mod 1000000007 using namespace std; const double INF = 0x3f3f3f3f; const int MAX = 1000 + 10; int m, n, pos, num; char s [52] [MAX], s1 [MAX], s2 [51]; // s1 is used to record the sequence with the smallest Lexicographic Order that meets the conditions, s2 is used to process the characters int main () {int T; cin> T; while (T --) {cin> m> n; int dis = 0; memset (s1, 0, sizeof (s1); num = 0; // getchar (); from (I, 0, m) cin> s [I]; from (I, 0, n) {pos = 0; int maxlen =-INF, cnt = 1; char c; from (j, 0, m) s2 [pos ++] = s [j] [I]; // extract all characters at position I (s2, s2 + pos ); // in ascending order, the first character found must be a small lexicographically small character c = s2 [0]; from (j, 1, pos) {if (s2 [j] = s2 [J-1]) cnt ++; else {if (maxlen
           
            

 

 

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.