hdu3183——A Magic Lamp(RMQ)
来源:互联网 发布:java随机读取数组的值 编辑:程序博客网 时间:2024/06/05 03:50
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
#include<iostream>#include<cstdio>#include<algorithm>#include<cstring>#include<cmath>#define N 1008#define LL long longusing namespace std;int dp[N][30];char s[N];int s1[N];void RMQ(int n){ int i,j; for(j=1; 1<<j<=n; j++) for(i=0; i+(1<<j)-1<n; i++) dp[i][j]=min(dp[i][j-1],dp[i+(1<<(j-1))][j-1]);}int main(){ int m,i,a,b; while(~scanf("%s%d",s,&m)) { int cat=0; int len=strlen(s); if(m>len) { puts("0"); continue; } else if(m<=0) { puts(s); continue; } for(i=0; i<len; i++) dp[i][0]=s[i]-'0'; RMQ(len); m=len-m;//选m个数 a=0,b=len-m;从[a,b]区间选 //LL sum=0;长度1000可能超限,所以用字符数组储存 while(m--) { int k=log(b-a+1.0)/log(2.0); int num=min(dp[a][k],dp[b-(1<<k)+1][k]); s1[cat++]=num; for(i=a; i<=b; i++) { if(s[i]==num+'0') break; } a=i+1,b++; } for(i=0; i<cat; i++) { if(s1[i]!=0) { break; } } if(i==cat) { puts("0"); continue; } for(i; i<cat; i++) printf("%d",s1[i]); cout<<endl; } return 0;}
阅读全文
0 0
- hdu3183——A Magic Lamp(RMQ)
- hdu3183—A Magic Lamp(RMQ,贪心)
- hdu3183 A Magic Lamp(RMQ)
- HDU3183 A Magic Lamp(RMQ)
- HDU3183 A Magic Lamp —— 贪心(单调队列优化)/ RMQ / 线段树
- HDU3183 A Magic Lamp (RMQ & ST)
- HDU3183 A Magic Lamp
- hdu3183 A Magic Lamp
- HDU3183 A Magic Lamp
- HDU3183-A Magic Lamp
- HDU3183 A Magic Lamp
- A Magic Lamp(RMQ)
- HDU3183 A Magic Lamp(线段树)
- hdu 3183 A Magic Lamp(RMQ)
- hdu 3183 A Magic Lamp(RMQ)
- hdu 3183 A Magic Lamp (RMQ)
- HDU 3183 A Magic Lamp(RMQ)
- hdu 3183 A Magic Lamp (RMQ)
- 匈牙利算法(二分图匹配)
- 费马小定理
- oracle 一些命令收集
- 工厂设计模式及理解
- 《信息网络传播视听许可证(视听许可证)》全解
- hdu3183——A Magic Lamp(RMQ)
- 布线时其他区域变黑、高亮Net时其他区域太黑
- leetcode 643. Maximum Average Subarray I
- this指向及this应用
- 快速排序
- 在centos环境使用yum安装环境搭建opencart
- hdu 2602 Bone Collector 01背包
- 随机函数(随机取数)
- Docker 常用命令集锦