HDU Analog Greedy 4550

Source: Internet
Author: User

Card Game time Limit: the/ +MS (java/others) Memory Limit:65535/32768K (java/Others) Total submission (s):1704Accepted Submission (s): -problem Description Xiao Ming recently house bored at home, so he invented a fun game, game props are n stacked cards, each card has a number, the number range is 0~9, the rules of the game are as follows: First take the top card on the table, then take the top card each time and put it on the table with the right or left side of the card sequence. When all n cards are placed on the table, the N cards on the table make up a number. This number cannot have a leading 0, which means that the number on the leftmost card cannot be 0.  The goal of the game is to make this number minimal. Now your task is to help Xiao Ming write a program, to find out the most decimal. The first line of input is a number T, which indicates that there is a T-group test data, and then there is a T-line, each line is a 0~a 9 string representing n cards stacked together, the leftmost number representing the top card. [Technical specification] T<= +1<= N <= -output for each set of test data, print the maximum number of decimal places you can get in a row. Sample Input356598765432109876105432Sample Output55612345678901678905432Source2013 Gold Shanxi Mountain Lodge Creative Game Program Challenge-Preliminary (2) recommendliuyiding| We have carefully selected several similar problems forYou:5634 5633 5632 5631 5630                     

      

1 /*2 Analysis: Give you a bunch of numbers in roughly divided into two cases 1: there are 0 2: no 03 There are two cases where 0 cannot be placed at the beginning of the4 now consider whether the combination of these two situations can be as5                                                                    */6 //Find the number of the given clock the most back and the smallest (the first time, not a 0) number, this number is placed at the beginning of the number followed by the number is placed at the bottom,7 //and then in addition to the number of digits left in front of the number also perform this operation (this time the smallest number can be 0) and then put in the middle of the last permutation number8#include <cstdio>9#include <cstring>Ten#include <algorithm> One using namespacestd; A intMain () - { -     Chara[111]; the     intb[111],i,j,q,m,n,l,miin,address,c[111],begin,end;//Begin and end represent the beginning and end of the unfilled part of the last queue . -scanf"%d",&n); -      while(n--) -     { +scanf"%s", a); -L=strlen (a); +          for(miin= +, i=0; i<l;i++) A         { atb[i]=a[i]-'0'; -         } -q=begin=0; -address=Ten; -          while(address) -         { in              for(i=0; i<l;i++) -             { to                 if(b[i]== One) +                      Break; -                 if(q==0) the                 { *                     if(miin>=b[i]&&b[i]!=0) $                     {Panax NotoginsengAddress=i;//find the last address with a minimum and a number ranging from 0 -miin=B[i]; the                     } +                 } A                 Else the                     if(miin>=B[i]) +                     { -address=i; $miin=B[i]; $                     } -             } -miin= +; theq++; -c[begin++]=b[address];Wuyib[address]= One; the         } -          for(i=0; i<begin;i++) Wuprintf"%d", C[i]); -          for(i=0; i<l;i++) About         { $             if(b[i]!= One) -printf"%d", B[i]); -         } -printf"\ n"); AMemset (A,'0',sizeof(a)); +     } the}

HDU Analog Greedy 4550

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.