A Magic Lamp HDU
来源:互联网 发布:java开发新技术 编辑:程序博客网 时间:2024/05/20 23:36
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?
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.
If the result contains leading zero, ignore it.
178543 4 1000001 1100001 212345 254321 2
1310123321
去掉m个数 就是选len-m个数 然而不能选len-m个最小的就完事了
所以这时候就要用一些技巧 让每次确实是在一段区间内找最小值
找规律可以发现(len-m)个数中的第一位一定在区间【1,m+1】中出现
假设第一位在第x位 那么第二位一定在[x+1,m+2]中出现 多么神奇 自己就是想不到QAQ
#include<bits/stdc++.h>using namespace std;int mmin[1005][20];int a[1005];int cal(int x,int y){ if(a[x]<=a[y]) return x; else return y;}void RMQ(int n){ for(int i=0;i<n;i++) mmin[i][0]=i; for(int j=1;j<20;j++) { for(int i=0;i+(1<<j)-1<n;i++) { //mmax[i][j]=max(mmax[i][j-1],mmax[i+(1<<(j-1))][j-1]); mmin[i][j]=cal(mmin[i][j-1],mmin[i+(1<<(j-1))][j-1]); } }}int query(int l,int r){ int k=log((double)(r-l+1))/log(2.0); return cal(mmin[l][k],mmin[r-(1<<k)+1][k]);}int main(){ char s[1005]; int m; while(scanf("%s%d",s,&m)!=-1) { memset(mmin,0,sizeof(mmin)); for(int i=0;s[i]!='\0';i++) { a[i]=(int)(s[i]-'0'); } int len=strlen(s); int n=len-m; RMQ(len); int ans[1005]; int i=0,j=0; while(n--) { i=query(i,len-n-1); ans[j++]=a[i++]; } for(i=0;i<j;i++) { if(ans[i]!=0)break; } if(j==i)cout<<"0"<<endl; else { while(i<j) printf("%d",ans[i]),i++; cout<<endl; } } return 0;}
阅读全文
0 0
- A Magic Lamp HDU
- A Magic Lamp HDU
- hdu 3183 A Magic Lamp
- HDU 1811 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
- EJB到底是什么,真的那么神秘吗??
- 用浮动代替定位解决动态变化的div内容,一个div浮在两个div上面
- css选择器-伪类选择器
- RMAN利用auxiliary复制数据库
- fstream读写UNICODE文件
- A Magic Lamp HDU
- Eclipse Gradle Buildship 插件的使用
- 闲聊软件测试自动化(2): 测试自动化的实践中我们有哪些困惑?
- 适配器模式(Adapter):类适配器、对象适配器
- HDU 1754 I Hate It(线段树)
- 对前端的认识及前端工程化
- 数据库事务系列-HBase行级事务模型
- json使用注意事项
- python入门(一)