Algorithm: efficient implementation of the problem of "no complex number", which is larger than the specified number and smallest

Source: Internet
Author: User

 

 

 

), So determine whether 19u is the number of duplicates (by simply judging whether 19u's single digit and ten digits are the same .).

), So the problem is to calculate the no-duplicated plural () of 2010u ().

).

 #include <stdio.h>     main(             ( i =  ; i <  +  ; i++       printf (  , i , find( i +                      printf(  , n ) ;             ( n <                 ( n /  < ( t = find( n /        n = t *          ( n %  == n / %         find( n +       }

# Include <stdio. h> typedef struct {unsigned char t [20]; // This space should be enough int top; // record the first subscript} Map; unsigned find (unsigned ); void parse (Map *, unsigned); int search (const Map *); void add_1 (Map *, const int); void clear (Map *, const int, const int ); unsigned combi (const Map *); int main (void) {unsigned iu; // test for (iu = 19922884u; iu <19922884u + 1u; iu ++) {printf ("% u \ n", iu, find (iu + 1u);} return 0;} unsigned combi (const Map * p_m) {unsigned nu = 0u; int I; for (I = p_m-> top; I> = 0; I --) {nu * = 10u; nu + = p_m-> t [I];} return nu;} void clear (Map * p_m, const int from, const int to) {int I; for (I = from-1; I> to-1; I --) p_m-> t [I] = 0u;} void add_1 (Map * p_m, const int from) {int I; p_m-> t [from] ++; // The Vertex plus 1 for (I = from; I <p_m-> top; I ++) // carry processing {p_m-> t [I + 1] + = p_m-> t [I]/10u; p_m-> t [I] % = 10u ;} if (p_m-> t [p_m-> top]> 9u) // The highest bit has a forward position {p_m-> t [p_m-> top + 1] = p_m-> t [p_m-> top]/10u; p_m-> t [p_m-> top ++] % = 10u ;}} int search (const Map * p_m) {int I; for (I = p_m-> top; i> 0; I --) {if (p_m-> t [I] = p_m-> t [I-1]) break;} return I-1 ;} void parse (Map * p_m, unsigned n) {p_m-> top =-1; while (n> 0u) {p_m-> t [++ p_m-> top] = n % 10u; n/= 10u ;}} unsigned find (unsigned n) {Map map; int end = 0, B _point; parse (& map, n); // splits n into numbers while (B _point = search (& map)>-1) // when the value is-1, it indicates that the number of duplicates is not {add_1 (& map, B _point); // Add 1 clear (& map, B _point, end) to the number of duplicates ); // change the value to 0 end = B _point later. // determine the processing range of the next loop.} return combi (& map );}

0 0 2

Related Article

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.