UVA1583 UVALive3355 Digit Generator

Source: Internet
Author: User

Regionals 2005 >> Asia-seoul

Problem Link: UVA1583 UVALive3355 Digit Generator. Basic Training level questions, written in C language.

To see test instructions, please click on the link above.

The tabular method is the most reasonable, even if there are too many possibilities, and it is more difficult to find the smallest generator.

The estimated time of not playing the table will also be timed out.

In the program, the table function is encapsulated into the function maketable (), which makes the main function concise. In addition, we need to pay attention to the array subscript overflow problem when playing the table. Also note that the minimum generated element is required.

The following C language programs are adopted by AC:

/* UVA1583 UVALive3355 Digit Generator */#include <stdio.h> #include <memory.h> #define MAXN 100000int ans[ Maxn+1];void maketable (int max) {    int i, Digitsum, N;    memset (ans, 0, sizeof (ans));    for (I=1; i<max; i++) {        digitsum = n = i;        while (n > 0) {            digitsum + = n;            n/=;        }        if (digitsum <= max)            if (ans[digitsum] = = 0)                Ans[digitsum] = i;    }} int main (void) {    maketable (MAXN);    int t, N;    scanf ("%d", &t);    while (t--) {        scanf ("%d", &n);        printf ("%d\n", Ans[n]);    }    return 0;}


UVA1583 UVALive3355 Digit Generator

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.