Hdu 1716 2

Source: Internet
Author: User

Hdu 1716 2

Learning:

1. Use the next_permutation () function in STL (use n for n numbers! Then we can get its full sorting amount:

Boolean next_permutation (. begin (),. end () This function is constructed by the characters in the input string in alphabetical order to determine whether there is another string after the current string. If the number of next_permutation executions is less than the total number of characters in the string, returns true. For example, if a = "abc" is fully arranged with "abc" acb "" bac "" bca "" cab "" CBA ", execute next_permutation once and return true a to" acb ". run next_permutation once and return true a to "bac "... when a = "CBA" is executed, because this is the last string in the full arrangement, if you execute next_permutation again, false is returned.

2. First, let's look at the lexicographically ordered order (a-z, 1-9 ). Based on the Lexicographic Order, we can obtain the size of any two numeric strings.

My code:

# Include
 
  
# Include
  
   
# Includeusing namespace std; int str [4]; // the four-digit number entered. Int shu [10000] [4], chu [1000] [4], t, h; // t indicates the number of elements in shu, and h indicates the number of elements in chu. Void painie (void); // sort the four numbers and store them in the shu []. The preceding figure shows that the first digit is 0 and the number is repeated. Void painie (void) {for (int I = 0; I <24; ++ I) // because it is 4! In all cases, 24 cycles {for (int j = 0; j <= 3; ++ j) {shu [t] [j] = str [j];} t ++; next_permutation (str, str + 4); // arrange the four elements in str each time. } Int main (void) {int kkk = 0; while (scanf ("% d", & str [0], & str [1], & str [2], & str [3]) & str [0] + str [1] + str [2] + str [3]) // exit when four values are zero at the same time. {If (kkk ++) printf ("\ n"); // output a blank row before each group of data, but the first group of data does not. Memset (shu, 0, sizeof (shu); memset (chu, 0, sizeof (chu); t = 0; h = 0; // initialization. Painie ();/* for (int j = 0; j
   
    
The following shows how to recursively arrange data:

/*µÝ¹éʵÏÖÈ«ÅÅÁУ¨22:44)*/#include
     
      #include
      
        char a[5],b[129][5];int ht=0;//¼Ç¼bÖÐÊý¾ÝÊýÁ¿¡£  void allsort( char str[],int n,int t);void swap(char str[],int a,int b);  void allsort(char str[],int n,int t)  {  if(ht==0){    for(int i=0;i<5;i++) b[ht][i]=str[i];ht++;}  if(n-t!=1)  {  for(int k=t;k
       
        


        

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.