A Magic Lamp

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 2937    Accepted Submission(s): 1145

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?
 
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.
 
Output
For each case, output the minimum result you can get in one line.

If the result contains leading zero, ignore it. 
 
Sample Input
178543 4
1000001 1
100001 2
12345 2
54321 2
 
Sample Output
13
1
0
123
321

我的天,这个题只要细心基本上没什么大问题,哎,,,,做的好辛苦啊,,思路也和NYOJ上贪心专题里的最大的数一样,,,可是把代码复制过来改改交却WA了一遍又一遍,,改的好辛苦,依旧错。。。

看起来都没多大区别:

#include<bits/stdc++.h>
using namespace std;
const int N=1001;
char a[N],b[N];
int main()
{
int n,i,j,k1,k2,k3,x1,x2;
while(~scanf("%s%d",a,&n))
{
memset(b,'0',sizeof(b));
x1=strlen(a);
if(x1==n)
{
printf("0\n");
continue;
}
else
{
j=k1=k3=0,k2=n,x2=x1-n;
char c;
while(x2--)
{
c=a[k1],k3=k1;
for(i=k1; i<=k2; i++)
{
if(k1==k2)
{
k3=k2;
break;
}
if(a[i]<c)
c=a[i],k3=i;
}
b[j++]=c,k1=k3+1,k2++;
}
for(i=0; i<j; i++)
if((b[i]!='0')||(i==j-1))
{
x2=i;
break;
}
for(i=x2; i<j; i++)
printf("%c",b[i]);
printf("\n");
}
}
return 0;
}

怎么说嘞,只能说做题沉心静气,细心~~

HDU3183A Magic Lamp,和NYOJ最大的数一样的更多相关文章

  1. hdu-3183A Magic Lamp(贪心)

    题目的意思是: 给你一个大数,然后删减其中的K个数,并且剩下的数还是按原来在的先后次序排列,求所得的那个数最小的那个数. 思路:贪心(要取得数最小,你从左往右选数的时候,选的第一数,就是选后组成数的位 ...

  2. HDOJ 3183 A Magic Lamp

    A Magic Lamp Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

  3. hdu 3183 A Magic Lamp(RMQ)

    题目链接:hdu 3183 A Magic Lamp 题目大意:给定一个字符串,然后最多删除K个.使得剩下的组成的数值最小. 解题思路:问题等价与取N-M个数.每次取的时候保证后面能取的个数足够,而且 ...

  4. A Magic Lamp(贪心+链表)

    A Magic Lamp Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

  5. hdu 3183 A Magic Lamp(RMQ)

    A Magic Lamp                                                                               Time Limi ...

  6. hdu 3183 A Magic Lamp rmq或者暴力

    A Magic Lamp Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Pro ...

  7. hdu A Magic Lamp

    http://acm.hdu.edu.cn/showproblem.php?pid=3183 A Magic Lamp Time Limit: 2000/1000 MS (Java/Others)   ...

  8. HDU_3183_A Magic Lamp

    A Magic Lamp Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

  9. HDU 3182 ——A Magic Lamp(思维)

    Description Kiki likes traveling. One day she finds a magic lamp, unfortunately the genie in the lam ...

随机推荐

  1. 162 Find Peak Element 寻找峰值

    峰值元素是指其值大于左右相邻值的元素.给定一个输入数组,其中 num[i] ≠ num[i+1],找到峰值元素并返回其索引.数组可能包含多个峰值,在这种情况下,返回到任何一个峰值所在位置都可以.你可以 ...

  2. 生成器的send方法

    send 和next区别 next:唤醒并继续执行 send:唤醒并继续执行 发送信息到生成器内部. def fib(max): n,a,b = 0,0,1 while n < max: msg ...

  3. 【学习笔记】深入理解js原型和闭包(18)——补充:上下文环境和作用域的关系

    本系列用了大量的篇幅讲解了上下文环境和作用域,有些人反映这两个是一回儿事.本文就用一个小例子来说明一下,作用域和上下文环境绝对不是一回事儿. 再说明之前,咱们先用简单的语言来概括一下这两个的区别. 0 ...

  4. 关于对象.style currentstyle 的区别

    对象.style的方式只能获取行内写法的样式,但是外部引入的或者写在head里面的就无法获取,只能用currentstyle.

  5. 深入理解Java的整型类型:如何实现2+2=5?

    先看下这段神奇的Java代码: public static void main(String[] args) throws Exception { doSomethingMagic(); System ...

  6. Netbeans调试教程

    官方教程:Netbeans调试 CC++ 项目教程.docx 1.步过: 就是把函数当成一条指令来调用 比如上面就是光执行fun(i),不会到函数里面去 2.步入 就是进入函数里面执行 3.步出 就是 ...

  7. uva12174 滑动窗口+预处理

    注意理解题意,不是排列种类,而是下一个排序出现的时间滑动窗口,具体见代码,写了很多注释(紫书的思路1理解有点麻烦...)注:可以画一个轴来方便理解 #include<iostream> # ...

  8. javascript.json snippets vscode 注释

    vscode vue js里面的注释 javascript.json { // Place your global snippets here. Each snippet is defined und ...

  9. Microsoft Windows Server

    Microsoft Windows Server Microsoft Windows Microsoft Windows 是微软推出的个人版操作系统: Microsoft Windows Server ...

  10. Echarts 异步数据加载遇到的问题

    看了Echarts官网异步加载数据的Demo var myChart = echarts.init(document.getElementById('main')); // 显示标题,图例和空的坐标轴 ...