http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1097
2
280
28023
2
280
2802
2
32
323231
First of all, the starting bit is relatively small, definitely in front of the. Then the key is how to deal with the same time, that is, 32 and 321 how to compare.
My approach: If the comparison is complete, the shorter one starts to compare. The equivalent of stitching up the loop
The source of what I want to do is:
It must be the same as the beginning of the same stack together, such as the beginning is 1 of the N, it must be the first n the first 1 of the heap. Because it's a better result.
So when they're 22 compared, if there's one missing, then it's up to the beginning of the supplement, then WA, after finding the data, just do it.
#include <cstdio>#include<cstdlib>#include<cstring>#include<cmath>#include<algorithm>#include<assert.h>#defineIOS Ios::sync_with_stdio (False)using namespacestd;#defineINF (0X3F3F3F3F)typedefLong Long intLL; #include<iostream>#include<sstream>#include<vector>#include<Set>#include<map>#include<queue>#include<string>#include<bitset>structNode {Charstr[ A]; intLenstr; BOOL operator< (Const structNode & RHS)Const { intnow =1; if(Lenstr <rhs.lenstr) { for(inti =1; I <= rhs.lenstr; ++i) {if(I >lenstr) { if(Str[now]! = Rhs.str[i])returnStr[now] <Rhs.str[i]; now++; if(Now > Lenstr) now =1; } Else { if(Str[i]! = Rhs.str[i])returnStr[i] <Rhs.str[i]; } } returnStr[now] < rhs.str[1]; } Else { for(inti =1; I <= lenstr; ++i) {if(I >rhs.lenstr) {if(Str[i]! = Rhs.str[now])returnStr[i] <Rhs.str[now]; now++; if(Now > Rhs.lenstr) now =1; } Else { if(Str[i]! = Rhs.str[i])returnStr[i] <Rhs.str[i]; } } returnstr[1] <Rhs.str[now]; } return false; }}a[11111];Const intMAXN = 1e6 + -;CharANS[MAXN];voidWork () {intN; scanf ("%d", &N); for(inti =1; I <= N; ++i) {scanf ("%s", A[i].str +1); A[i].lenstr= strlen (A[i].str +1); } sort (A+1, A +1+N); intLenans =0; for(inti =1; I <= N; ++i) {strcpy (ans+ Lenans +1, A[i].str +1); Lenans+=A[i].lenstr; } for(inti =1; I <= Lenans; ++i) {printf ("%c", Ans[i]); ifI +==0) {printf ("\ n"); } }}intMain () {#ifdef local freopen ("Data.txt","R", stdin);//freopen ("Data.txt", "w", stdout);#endifWork (); return 0;}
View Code
1097 spell the smallest number greedy sort