首页 技术 正文
技术 2022年11月14日
0 收藏 445 点赞 2,808 浏览 2228 个字

A Magic Lamp

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2521    Accepted Submission(s): 986

Problem DescriptionKiki
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? InputThere 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. OutputFor each case, output the minimum result you can get in one line.
If the result contains leading zero, ignore it.  Sample Input178543 4
1000001 1
100001 2
12345 2
54321 2 Sample Output13
1
0
123
321 题解:给一个数,去掉一部分后得到的数最小,真是写醉了。。。各种wa,最后都想到了负数,思路没错,就是贪心,找到n[i]>n[j]就减去i这个数,最后过了,现在仍然感觉自己思路每错,换种写法就会ac。。。代码:

 #include<cstdio>
#include<cstring>
#define mem(x,y) memset(x,y,sizeof(x))
const int MAXN=;
char n[MAXN];
int vis[MAXN];
int main(){
int m,t;
while(~scanf("%s%d",n,&m)){
mem(vis,);
t=strlen(n);
int r=t-;
for(int i=;i<m;i++){
int cnt=;
for(int j=;j<r;j++){
if(vis[j])continue;
int x=j+;
while(vis[x])x++;//
if(n[j]>n[x]){
vis[j]=;cnt=;break;
/*比赛时候这样写的,一直wa仍然感觉没错。。。
if(n[j]<n[j+1]){
cnt=1;
vis[j]=1;
n[j]=n[j+1];
break;
}
*/
}
}
if(!cnt)vis[r--]=;
}int flog=;
for(int i=;i<t;i++){
if(vis[i])continue;
if(flog&&n[i]=='')continue;
flog=;printf("%c",n[i]);
}
if(flog)printf("");
puts("");
}
return ;
}

链表:

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
#define mem(x,y) memset(x,y,sizeof(x))
const int MAXN=;
struct Node{
int pre,next,val;
};
Node lis[MAXN];
char s[MAXN];
int main(){
int n,len;
while(~scanf("%s%d",s,&n)){
mem(lis,);
len=strlen(s);
for(int i=;i<=len;i++){
lis[i].pre=i-;
lis[i].val=s[i-]-'';
lis[i].next=i+;
}
lis[].next=;lis[len+].pre=len;
int p,q;
while(n--){
p=;
while(p!=len+){
q=lis[p].next;
if(lis[p].val>lis[q].val){
lis[q].pre=lis[p].pre;
q=lis[p].pre;lis[q].next=lis[p].next;
break;
}
p=lis[p].next;
}
}
p=;
while(lis[p].val==&&p!=len+)p=lis[p].next;
if(p==len+)puts("");
else{
while(lis[p].next!=n+){
printf("%d",lis[p].val);p=lis[p].next;
}
puts("");
}
}
return ;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,494
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,907
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,740
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,495
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,133
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,297