HDU 3183 A Magic Lamp
来源:互联网 发布:域名信息隐藏 编辑:程序博客网 时间:2024/05/19 08:41
A Magic Lamp
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4690 Accepted Submission(s): 1945
Problem Description
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?
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?
Input
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.
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.
Output
For each case, output the minimum result you can get in one line.
If the result contains leading zero, ignore it.
If the result contains leading zero, ignore it.
Sample Input
178543 4 1000001 1100001 212345 254321 2
Sample Output
1310123321
贪心,每次往后面的数字找一遍,如果他的后面有比他小的数,就将其标记
#include<iostream>#include<cstring>#include<cstdio>using namespace std;char str[1010];int num[1010];int main(){//freopen("in.txt","r",stdin);int n;while(~scanf("%s%d",str,&n)){memset(num,0,sizeof(num));int len=strlen(str);for(int i=0;i<len;i++){num[i]=str[i]-'0';}while(n--){for(int i=0;i<len;i++){if(num[i]==-1) continue;int j;for(j=i+1;j<len;j++){if(num[j]>=0){break;}}if(num[i]>num[j]){num[i]=-1;break;}}}int flag=0;for(int i=0;i<len;i++){if(num[i]==-1) continue;if(!flag&&num[i]==0) continue;flag=1;cout<<num[i];}if(!flag) cout<<0;cout<<endl;}}
阅读全文
0 0
- hdu 3183 A Magic Lamp
- hdu 3183 A Magic Lamp
- hdu 3183 A Magic Lamp
- Hdu 3183 A Magic Lamp
- HDU 3183 A Magic Lamp
- HDU 3183 A Magic Lamp
- hdu 3183 A Magic Lamp
- hdu 3183 A Magic Lamp
- HDU 3183 A Magic Lamp
- HDU-3183-A Magic Lamp
- hdu 3183 A Magic Lamp
- HDU-3183-A Magic Lamp
- hdu 3183 A Magic Lamp
- HDU-3183-A Magic Lamp
- HDU 3183 A Magic Lamp
- A Magic Lamp HDU
- A Magic Lamp HDU
- hdu 3183 A Magic Lamp(模拟解法)
- 回顾大一·C语言编程3.3(2)
- BZOJ 1096 [ZJOI2007]仓库建设 动态规划+斜率优化
- AlexNet
- 关于writes写入次数的误区
- 回顾大一·C语言编程3.4(1)
- HDU 3183 A Magic Lamp
- 454. 4Sum II
- java总结
- 洛谷·P2386 放苹果
- 文本三剑客之sed
- Publishing failed with multiple errors Could not delete *,May be locked by another process.
- Typora-changelog-0.9.37 (beta)
- 刷题记录
- StateListDrawable资源