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. Java异常概念

  2. 492 Construct the Rectangle 构建矩形

    详见:https://leetcode.com/problems/construct-the-rectangle/description/ C++: class Solution { public: ...

  3. 牛客网Java刷题知识点之自动拆装箱

    不多说,直接上干货! https://www.nowcoder.com/ta/review-java/review?query=&asc=true&order=&page=5 ...

  4. Git之删除本地和远程项目

    目录 删除本地项目 删除远程项目 删除本地项目: git rm -rf project  或者 rm -rf project   [删除工作区项目] git add project [将删除的项目添加 ...

  5. hihocoder1078 线段树的区间修改

    思路: 线段树区间更新.注意这里是把一个区间的所有数全部赋值为一个新的值. 实现: #include <bits/stdc++.h> using namespace std; ; ], l ...

  6. Web前端开发的四个阶段(小白必看)

    第一阶段:HTML的学习 超文本标记语言(HyperText Mark-up Language 简称HTML)是一个网页的骨架,无论是静态网页还是动态网页,最终返回到浏览器端的都是HTML代码,浏览器 ...

  7. sql查询作业执行时间

    SELECT  j.name                        AS Job_Name        ,        h.step_id                     AS S ...

  8. codevs 2905 足球晋级

    时间限制: 1 s  空间限制: 64000 KB  题目等级 : 黄金 Gold   题目描述 Description A市举行了一场足球比赛 一共有4n支队伍参加,分成n个小组(每小组4支队伍)进 ...

  9. python调用脚本或shell的方式

    python调用脚本或shell有下面三种方式: os.system()特点:(1)可以调用脚本.(2)可以判断是否正确执行.(3)满足不了标准输出 && 错误 commands模块特 ...

  10. mysql查询-从表1中查询出来的结果重新插入到表1

    原有表结构 CREATE TABLE `t_card_user` ( `id` varchar(32) NOT NULL, `card_user_id` bigint(20) DEFAULT NULL ...