hdoj--3183--A Magic Lamp(贪心)
A Magic Lamp
Total Submission(s): 2584 Accepted Submission(s): 1010
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 1
100001 2
12345 2
54321 2
13
1
0
123
321
#include<stdio.h>
#include<string.h>
char s[1010];
int vis[1010];
int a[1010];
int main()
{
int i,j,k,l,n,m;
while(scanf("%s",s)!=EOF)
{
scanf("%d",&m);
l=strlen(s);
for(i=0;i<l;i++)
a[i]=s[i]-'0';
n=0;
int mm=m;
memset(vis,0,sizeof(vis));
while(mm--)
{
for(i=0;i<l-1;i++)
{
if(!vis[i])
{
j=i+1;
while(vis[j])
j++;
if(a[i]>a[j])
{
vis[i]=1;
n++;
break;
}
}
}
}
int kk=m-n;
for(i=l-1;i>=0;i--)
{
if(!vis[i]&&kk)
{
vis[i]=1;
kk--;
}
}
int flag=0;
int p=0;
for(i=0;i<l;i++)
{
if(!vis[i])
{
if(s[i]!='0')
flag=1;
if(flag)
{
printf("%c",s[i]);
p++;
}
}
}
if(p==0)
printf("0");
printf("\n");
}
return 0;
}
hdoj--3183--A Magic Lamp(贪心)的更多相关文章
- HDOJ 3183 A Magic Lamp
A Magic Lamp Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tota ...
- hdu 3183 A Magic Lamp 贪心
#include <stdio.h> #include <string.h> #include <iostream> #include <algorithm& ...
- hdu 3183 A Magic Lamp(RMQ)
题目链接:hdu 3183 A Magic Lamp 题目大意:给定一个字符串,然后最多删除K个.使得剩下的组成的数值最小. 解题思路:问题等价与取N-M个数.每次取的时候保证后面能取的个数足够,而且 ...
- hdu 3183 A Magic Lamp RMQ ST 坐标最小值
hdu 3183 A Magic Lamp RMQ ST 坐标最小值 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3183 题目大意: 从给定的串中挑 ...
- HDU 3183 - A Magic Lamp - [RMQ][ST算法]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3183 Problem DescriptionKiki likes traveling. One day ...
- hdu 3183 A Magic Lamp(RMQ)
A Magic Lamp Time Limi ...
- HDU 3183 A Magic Lamp(RMQ问题, ST算法)
原题目 A Magic Lamp Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- hdu 3183 A Magic Lamp rmq或者暴力
A Magic Lamp Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Pro ...
- 【HDOJ】3183 A Magic Lamp
RMQ. /* 3183 */ #include <cstdio> #include <cstring> #include <cstdlib> #define MA ...
- HDU3183 A Magic Lamp —— 贪心(单调队列优化)/ RMQ / 线段树
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3183 题解: 方法一:贪心. 在草稿纸上试多几次可以知道,删除数字中从左到右最后一位递增(可以等于)的 ...
随机推荐
- poj 3259 bellman最短路推断有无负权回路
Wormholes Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 36717 Accepted: 13438 Descr ...
- shell文本过滤编程(一):grep和正則表達式
[版权声明:转载请保留出处:blog.csdn.net/gentleliu.Mail:shallnew at 163 dot com] Linux系统中有非常多文件,比方配置文件.日志文件.用户文件等 ...
- 如何获取Assets的路径
有两种方法可以获取assets的绝对路径: 第一种方法: String path = file:///android_asset/文件名; 第二种方法: InputStream abpath = ge ...
- Authentication in asp.net
https://docs.microsoft.com/en-us/aspnet/web-forms/overview/older-versions-security/introduction/an-o ...
- Vmware Workstation及Centos6.8 的安装
转自:http://www.mamicode.com/info-detail-1462939.html 一.什么是Vmware Workstation Vmware Workstation是Vmwar ...
- [JZOJ 100026] [NOIP2017提高A组模拟7.7] 图 解题报告 (倍增)
题目链接: http://172.16.0.132/senior/#main/show/100026 题目: 有一个$n$个点$n$条边的有向图,每条边为$<i,f(i),w(i)>$,意 ...
- STM8S103内存详析
STM8S103的RAM有1k,0x00-0x3FF(RAM和ROM统一编址),其中0x200-0x3ff共512个字节默认为堆栈,剩余的低端512个字节又分为了Zero Page和剩余的RAM(简称 ...
- CorelDRAW X6低价再次冲破底线
平时我们看到的标志设计.杂志排版.产品商标.插图描画......这些都是设计师们使用CorelDRAW设计而来.如今CorelDRAW已经成为每个设计师必装的软件,从12年发布CorelDRAW X6 ...
- RegExp javascript正则表达式 :
传统的查找字符串中的相关的字符 :<script type="text/javascript">var str='aaa23uihjkikh666jhjhk888kuh ...
- 记录python之递归函数
函数move(n,a,b,c)的定义是将n个圆盘从a借助b移动到c. def move(n,a,b,c): if n==1: print a,'-->',c move (n-1,a,c,b) p ...