HDU 3183 A Magic Lamp rmq or violence

Source: Internet
Author: User
Tags cmath

A Magic Lamp

Time limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)


Problem Descriptionkiki likes traveling. One day she finds a magic lamp, unfortunately the genie in the lamp is not so kind. Kiki must answer a question, and then the Genie would realize one of her dreams.
The question is:give you a integer, you is allowed to delete exactly m digits. The left digits would form a new integer. You should make it minimum.
You aren't allowed to the order of the digits. Now can-you-help Kiki-realize her dream?

Inputthere is several test cases.
Each of the test case would contain an integer given (which could at most contains-digits.) and the integer m (if the I Nteger contains n digits, m won't bigger then N). The given integer would not contain leading zero.

Outputfor each case, the output of the minimum result can get in one line.
If The result contains leading zero, ignore it.

Sample Input178543 4 1000001 1100001 212345 254321 2

Sample Output1310123321

SOURCEHDU 2009-11 Programming Contest Test Instructions: give you a number, in 1000 bits (string), delete the number of M, to get the minimum number of output; RMQ: Thought: First in the len-m; after finding the nth bit Finally left no number of numbers (len-m-n), in the interval after n to find n+1; (0ms)
#include <iostream>#include<cstdio>#include<cmath>#include<string>#include<queue>#include<algorithm>#include<stack>#include<cstring>#include<vector>#include<list>#include<Set>#include<map>using namespacestd;#definell Long Long#defineMoD 1000000007#defineINF 999999999intScan () {intres =0, ch;  while( ! (ch = getchar ()) >='0'&& CH <='9' ) )    {        if(ch = = EOF)return 1<< - ; } Res= CH-'0' ;  while(ch = getchar ()) >='0'&& CH <='9') Res= Res *Ten+ (CH-'0' ) ; returnRes;}Chara[10100];intdp[10100][ -];//Storage locationCharans[10100];intMinn (intXinty) {    returnA[x]<=a[y]?x:y;}voidRmqintLen) {     for(intI=0; i<len; i++) dp[i][0]=i;  for(intj=1; (1&LT;&LT;J) <len; J + +)     for(intI=0; i+ (1&LT;&LT;J)-1<len; i++) Dp[i][j]=minn (dp[i][j-1],dp[i+ (1<< (J-1))][j-1]);}intQueryintLintR) {    intX= (int) (Log (Double) (r-l+1))/log (2.0)); returnMinn (dp[l][x],dp[r-(1&LT;&LT;X) +1][x]);}intMain () {intx,y,z,i,t;  while(~SCANF ("%s%d",a,&x)) {intlen=strlen (a);        RMQ (len); intst=0, en=x; intflag=0;  for(i=0; i<len-x; i++)        {            intNumber=query (St,en); //cout<<st<< "" <<en<< "" <<number<<endl;st=number+1; En=i+x+1; Ans[flag++]=A[number]; }         for(i=0; i<flag; i++)            if(ans[i]!='0')                 Break;  for(t=i; t<flag; t++) printf ("%c", ans[t]); if(i==flag) printf ("0"); printf ("\ n"); }}
View Code

The idea of violence: finding a[i]>a[i+1]; in a string finds the first to be deleted; if not, the description is always up; the last number is the largest, and the last one is deleted;

#include <iostream>#include<cstdio>#include<cmath>#include<string>#include<queue>#include<algorithm>#include<stack>#include<cstring>#include<vector>#include<list>#include<Set>#include<map>using namespacestd;#definell Long Long#defineMoD 1000000007#defineINF 999999999intScan () {intres =0, ch;  while( ! (ch = getchar ()) >='0'&& CH <='9' ) )    {        if(ch = = EOF)return 1<< - ; } Res= CH-'0' ;  while(ch = getchar ()) >='0'&& CH <='9') Res= Res *Ten+ (CH-'0' ) ; returnRes;} Vector<int>v;Chara[1010];intMain () {intx,y,z,i,t;  while(~SCANF ("%s%d",a,&x)) {v.clear (); intlen=strlen (a);  for(i=0; i<len; i++) V.push_back (A[i]-'0');  while(x--)        {            intflag=1; intlen=v.size ();  for(i=0; i<len-1; i++)            {                if(v[i]>v[i+1]) {flag=0; V.erase (V.begin ()+i);  Break; }            }            if(flag) V.erase (V.begin ()+len-1); }         for(i=0; I<v.size (); i++)            if(V[i]) Break;  for(t=i; t<v.size (); t++) printf ("%d", v[t]); if(i==v.size ()) printf ("0"); printf ("\ n"); }    return 0;}
View Code

HDU 3183 A Magic Lamp rmq or violence

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.