Hdu 3183 a Magic Lamp (give an n-bit number, delete m numbers from it, make the number of the remaining numbers the smallest (order cannot be changed), and then output)

Source: Internet
Author: User

1.The main idea is, to give you a 1000-digit number, you want to delete m for, the result is the most decimal.

Idea: in n bits inside delete m digit, that is to find n-m digit composition the most decimal

So find the smallest number in the interval [0, M] , the corresponding subscript label I

Then find the minimum number in the interval [i+1,m++] , for the Subscript II

Then find the minimum number in the interval [ii+1,m++] ...

This will find the number of n-m. The purpose of this arrangement is to guarantee the order of the numbers taken out.


2 Code:

#include <cstdio> #include <cstring> #include <cmath> #define Min (a) (a) < (b)? A):(B)) using namespace Std;char s[10005];int a[10005];int an[10005];int st[10005][20];int n,m;void make_st ()// The lowest value of the subscript {for (int j=1) is recorded; (1&LT;&LT;J) <=n; J + +) {for (int i=1; (i+ (1&LT;&LT;J)-1) <=n; i++) {if (a[st[i][j-1]]<=a[st[i+ (1<< (j-1))][j-1])//equals equal to two numbers when the smaller st[i][j is removed            ]=ST[I][J-1];        Else st[i][j]=st[i+ (1<< (j-1))][j-1];    }}}int Query (int l,int r) {int K=floor (log2 (r-l+1));    int ans;    if (a[st[l][k]]<=a[st[r-(1<<k) +1][k]]) ans=st[l][k];    else ans=st[r-(1<<k) +1][k]; return ans;}        int main () {while (scanf ("%s%d", S,&m) ==2) {N=strlen (s);            for (int i=0; i<n; i++) {a[i+1]= (s[i]-' 0 ');        st[i+1][0]=i+1;        } make_st ();        int t=1;        int temp=1; for (int i=m+1; i<=n; i++)//Find N-mThe smallest {t=query (t,i) from [t,i] each time;        An[temp++]=a[t++];        } t=1;        while (t<temp&&an[t]==0) t++;        if (t>=temp) printf ("0\n");            else {for (int i=t; i<temp; i++) printf ("%d", an[i]);        printf ("\ n"); }} return 0;}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Hdu 3183 a Magic Lamp (give an n-bit number, delete m numbers from it, make the number of the remaining numbers the smallest (order cannot be changed), and then output)

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.