UVA 11491 Erasing and Winning

Source: Internet
Author: User

Test instructions

Give you an n-bit integer, let you delete the D number, the remaining number should be as large as possible.

Analysis:

Vector array simulation was used. If the number of the last digit in the >vector array that is currently being inserted is replaced and d--

Code:

  

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace Std;
Vector<char> s;
int main ()
{
int n,d;
while (~SCANF ("%d%d", &n,&d) &&n)
{
int len=n-d;
S.clear ();
GetChar ();
for (int i=0;i<n;++i)
{
Char C=getchar ();
if (S.size () >0)
{
int p= (int) s.size ()-1;
while (d&&c>s[p]&&p>=0)
{
S.erase (S.begin () +p--);
--d;
}
}
if (S.size ()!=len)
S.push_back (c);
else--d;
}
for (int i=0;i<s.size (); ++i)
cout<<s[i];
printf ("\ n");
}
return 0;
}

UVA 11491 Erasing and Winning

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.