您的位置:首页 > 其它

hdu 3183 A Magic Lamp rmq或者暴力

2016-04-13 19:54 330 查看

A Magic Lamp

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)


[align=left]Problem Description[/align]
Kiki 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 will realize one of her dreams.
The question is: give you an integer, you are allowed to delete exactly m digits. The left digits will form a new integer. You should make it minimum.
You are not allowed to change the order of the digits. Now can you help Kiki to realize her dream?

[align=left]Input[/align]
There are several test cases.
Each test case will contain an integer you are given (which may at most contains 1000 digits.) and the integer m (if the integer contains n digits, m will not bigger then n). The given integer will not contain leading zero.

[align=left]Output[/align]
For each case, output the minimum result you can get in one line.
If the result contains leading zero, ignore it.

[align=left]Sample Input[/align]

178543 4
1000001 1
100001 2
12345 2
54321 2

[align=left]Sample Output[/align]

13
1
0
123
321

[align=left]Source[/align]
HDU 2009-11 Programming Contest
题意:给你一个数,在1000位内(字符串),删掉m个数,得到最小的数输出;
rmq :思路:第一位在len-m内;找到第n位以后,最后留下没有找数的数目(len-m-n),在n之后的区间找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 namespace std;
#define ll long long
#define mod 1000000007
#define inf 999999999
int scan()
{
int res = 0 , ch ;
while( !( ( ch = getchar() ) >= '0' && ch <= '9' ) )
{
if( ch == EOF ) return 1 << 30 ;
}
res = ch - '0' ;
while( ( ch = getchar() ) >= '0' && ch <= '9' )
res = res * 10 + ( ch - '0' ) ;
return res ;
}
vector<int>v;
char a[1010];
int main()
{
int x,y,z,i,t;
while(~scanf("%s%d",a,&x))
{
v.clear();
int len=strlen(a);
for(i=0; i<len; i++)
v.push_back(a[i]-'0');
while(x--)
{
int flag=1;
int len=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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: