Uvalive 7203 at the most twice

Source: Internet
Author: User

title Link:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ problem&problem=5215

Test Instructions: Give a number U (1≤u≤1018), ask for a maximum number smaller than u, this number to meet in this number of each number not more than 2 times.

idea:DFS search maintains an array of records of how many times each number has been present.

1 //#include <bits/stdc++.h>2#include <cstring>3#include <cstdio>4#include <string>5#include <iostream>6 using namespacestd;7 Long LongU;8 intnum[ -];9 intans[ -];Ten intmark[ A]; One intLen; A BOOLFind; - voidDfsintCurintlimit) - { the    if(Find)return; -    if(Cur <0) -    { -        BOOLFlag =true; +         for(inti = len-1; I >=0; i--) -        { +            if(flag && ans[i] = =0)Continue; A            Else if(Flag && ans[i]! =0) at            { -printf"%d", Ans[i]); -Flag =false; -            } -            Elseprintf"%d", Ans[i]); -        } inprintf"\ n"); -Find =true; to        return; +    }  -    intup = Limit?num[cur]:9; the     for(inti = up; I >=0; i--) *    { $        if(Mark[i] >=2)Continue;Panax Notoginsengmark[i]++; -Ans[cur] =i; theDFS (cur-1, limit && i = =Up ); +        if(Find)return; Amark[i]--; the    } +    return; -     $ } $ voidSlove (Long Longx) - { -Len =0; the      while(x) -     {Wuyinum[len++] = x%Ten; theX/=Ten; -     } Wumemset (Mark,0,sizeof(Mark)); -DFS (len-1,1); About } $ intMain () - { -   //freopen ("In.txt", "R", stdin); -   //freopen ("OUT.txt", "w", stdout); A      while(~SCANF ("%lld", &U)) +     { theFind =false; - Slove (U); $     } the     return 0; the}

Uvalive 7203 at the most twice

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.