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. 132 Palindrome Partitioning II 分割回文串 II

    给定一个字符串 s,将 s 分割成一些子串,使每个子串都是回文串.返回 s 符合要求的的最少分割次数.例如,给出 s = "aab",返回 1 因为进行一次分割可以将字符串 s 分 ...

  2. 如何修改phpmyadmin上传文件大小限制

    修改php配置文件,php.ini upload_max_filesize = 100M post_max_size = 100M 一般修改这2个就行了,然后重启wampserver 如果还不行,就执 ...

  3. Node.Js的Module System 以及一些常用 Module

    Node.Js学习就按照这本书的流程来. 在第7章结束与第10章结束时分别自己出一个小项目练练手.Node.Js的入门学习计划是这样. 目录:, QQ:1045642972 欢迎来索书以及讨论Node ...

  4. mybatis generator 整合lombok

    <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE generatorConfiguration ...

  5. flask搭建

    1.定义路由app.py from flask import Flask, request from flask import Blueprint app = Flask(__name__) test ...

  6. VS Code使用技巧整理

    转自:https://blog.csdn.net/u011127019/article/details/58586129 https://blog.csdn.net/sgdd123/article/d ...

  7. 关于php的问题

    $polling_items = db_fetch_assoc("SELECT * FROM poller_item WHERE rrd_next_step<=0 ORDER by h ...

  8. toast插件的简单封装(样式适用pc后台管理系统的场景)

    直接分三个步骤吧: 1.手写一个toast.vue组件 <template> <transition name="toast-fade"> <div ...

  9. 51nod 1097 拼成最小的数

    基准时间限制:1 秒 空间限制:131072 KB 分值: 20 难度:3级算法题  收藏  关注 设有n个正整数,将它们联接成一排,组成一个最小的多位整数.     例如: n=2时,2个整数32, ...

  10. PHP一句话后门过狗姿势万千之理论篇

    写在前面: 过狗相关的资料网上也是有很多,所以在我接下来的文章中,可能观点或者举例可能会与网上部分雷同,或者表述不够全面. 但是我只能说,我所传达给大家的信息,是我目前所掌握或者了解的,不能保证所有人 ...