Background: 1--tle: timeout, without taking into account the complexity of the time, began to each number from 1 to 99999, so that is O (t*key) so that 20 groups of large number can be timed out. 2--wa:3--wa are the numbers mistakenly think up to 4 bits, in fact, five bit!!!
Idea: Find out that I (from 1 to 100000) produces a number of n,i is the generation of N, because up to 5 digits are added, so n-i<50. For each number of T to find the generator, if T is greater than 50, just search (t-50,t).
Study: 1. For all cases up to 100,000 levels can be played on the table.
#include <stdio.h>int str[99999];int main (void) { str[0]=0; for (int i=1;i<99999;i++) { int temp=i; str[i]=i; for (int j=0;j<5;j++) { str[i]+=temp%10; temp/=10; } } int t; scanf ("%d", &t); while (t--) { int key,judege=0; scanf ("%d", &key); for (int i=1;i<99999;i++) { if (i==1) { if (key>50) i=key-50; } if (str[i]==key) { judege=1; printf ("%d\n", I); break; } } if (!judege) printf ("0\n"); } return 0; }
UVa 1583 Dozen Watches