SDUTOJ 2072 删数问题 贪心
来源:互联网 发布:手机电子表格办公软件 编辑:程序博客网 时间:2024/05/22 02:29
删数问题
Time Limit: 1000MS Memory limit: 65536K
题目描述
键盘输入一个高精度的正整数n(≤100位),去掉其中任意s个数字后剩下的数字按照原来的左右次序组成一个新的正整数。编程对给定的n与s,寻找一种方案,使得剩下的数字组成的新数最小。
输入
输入有多组 每组包括原始数n,要去掉的数字数s;
输出
输出去掉s个数后最小的数
示例输入
178543 4
示例输出
13
提示
来源
示例程序
#include <stdio.h>#include <string.h>struct node{ char ch; node *next;};char s[110];int main(){ node *head = new node,*p,*q; int n; while(~scanf("%s%d",s,&n)) { head->next = NULL; p = head; int len = strlen(s); int llen = len; if(len <= n) { printf("0\n"); continue; } for(int i = 0; i < len; i++) { q = new node; q->ch = s[i]; p->next = q; q->next = NULL; p = q; } while(n) { p = head->next; q = head; while(p->ch == '0') { node *r = p->next; q->next = r; delete p; p = r; llen--; } if(llen <= n) { printf("0\n"); break; } while(p->next != NULL) { if(p->ch <= p->next->ch) { q = p; p = p->next; } else break; } q->next = p->next; delete p; llen--; n--; } if(llen > n) { p = head->next; while(p && p->ch == '0') p = p->next; if(!p) printf("0"); while(p) { printf("%c",p->ch); p = p->next; } printf("\n"); } } return 0;}
0 0
- SDUTOJ 2072 删数问题 贪心
- SDUTOJ 2074 区间覆盖问题 贪心
- 【贪心】删数问题
- 【贪心】删数问题
- 贪心 删数问题
- 贪心,删数问题
- [贪心] 删数问题
- 删数问题 贪心
- [贪心]删数问题
- 贪心 -- 删数问题
- 贪心算法例题:2072删数问题
- [SDUT](2072)删数问题 ---贪心
- 【贪心】【RQNOJ】删数问题
- 贪心算法 - 删数问题
- 删数问题(贪心)
- 贪心算法-删数问题
- 删数问题(贪心)
- 贪心算法---删数问题
- IRP
- FPGA LVDS应用
- 在使用caffe的时候,如何设置GPU的ID号
- Android Volley完全解析(一),初识Volley的基本用法
- lucene查询
- SDUTOJ 2072 删数问题 贪心
- supervisord.conf
- 每日一题之排序算法专题
- (转载)Android数据库高手秘籍(七)——体验LitePal的查询艺术
- MySQL Daemon failed to start解决方法
- Android抽象布局——include、merge 、ViewStub
- DOM元素的childNodes和children的区别
- 图像处理相关的重要期刊汇总
- git修改默认编辑器