UVA 1583 Digit Generator (Uva-1583)

Source: Internet
Author: User

The title is no longer written, vj:https://vjudge.net/problem/uva-1583#author=0.

The main thing is to find a number less than it's a number, less than its number each add up plus that number will be equal to the original number. No, it's 0.

The problem actually feels like a direct violence for the right. The largest number is 1e5. So up to 5 9 so that's 45, just use StringStream or other methods to split the position and look for the line.

Find the break then this number is the smallest.

Rujia's practice is to directly preprocess an array and then find the number based on the array, it is very smart, and the code is also relatively small.

Code:

#include <iostream>using namespacestd;#defineMax 100010intA[max];main () { for(intI=1; i<max;i++)    {        intX=i;inty=i;  while(x) {y+=x%Ten; x/=Ten;} if(a[y]==0|| I<a[y]) a[y]=i; }    intp,b; CIN>>p;  while(p--) {cin>>b; cout<<a[b]<<Endl; }}

This kind of thought should pay attention to!!! Direct preprocessing.

UVA 1583 Digit Generator (Uva-1583)

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.