hdu A Magic Lamp
http://acm.hdu.edu.cn/showproblem.php?pid=3183
A Magic Lamp
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2556 Accepted Submission(s): 999
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.
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm> using namespace std; typedef long long ll;
const int N = ; int main()
{
char s[N];
int a[N], str[N];
int m, i;
while(~scanf("%s%d", s, &m))
{
memset(str, , sizeof(str));
int k = , l = strlen(s);
for(i = ; s[i] != '\0' ; i++)
a[i] = s[i] - '';
for(i = ; i < l && m > ; i++)
{
if(a[i] <= a[i + ])
str[k++] = a[i];
else
{
m--;
while(str[k - ] > a[i + ] && m > && k >= )
{
m--;
k--;
}
}
}
for(; i < l ; i++)
str[k++] = a[i];
for(i = ; i < k - m ; i++)
if(str[i] != )
break;
if(i == k - m)
printf("");
else
{
for(int j = i ; j < k - m ; j++)
printf("%d", str[j]);
}
printf("\n");
}
return ;
}
hdu A Magic Lamp的更多相关文章
- 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 ...
- A Magic Lamp -- hdu -- 3183
http://acm.hdu.edu.cn/showproblem.php?pid=3183 A Magic Lamp Time Limit: 2000/1000 MS (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 ...
- hdu 3183 A Magic Lamp(RMQ)
A Magic Lamp Time Limi ...
- HDU 3182 ——A Magic Lamp(思维)
Description Kiki likes traveling. One day she finds a magic lamp, unfortunately the genie in the lam ...
- A Magic Lamp HDU - 3183 (逆向贪心/RMQ)
Kiki likes traveling. One day she finds a magic lamp, unfortunately the genie in the lamp is not so ...
- HDU 3183 A Magic Lamp(RMQ问题, ST算法)
原题目 A Magic Lamp Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
随机推荐
- 【c++】多层次继承类对象的构造函数参数的传递方法
#include <iostream.h> //基类CBase class CBase { int a; public: CBase(int na) { a=na; cout<< ...
- SQL2000清除SQL日志
1.打开查询分析器,输入命令DUMP TRANSACTION 数据库名 WITH NO_LOG2.再打开企业管理器--右键你要压缩的数据库--所有任务--收缩数据库--收缩文件--选择日志文件--在收 ...
- 4-js 函数
总是有些奇奇怪怪的问题: <div> <p class="productStatus"> <span>成交量 <em>${goods ...
- WPF之DataGrid控件根据某列的值设置行的前景色(色
一种方法是 使用 datagrid的LoadingRow事件: private void DataGrid_LoadingRow(object sender, DataGridRowEventArgs ...
- 使用PHP-GTK编写一个windows桌面应用程序
PHP-GTK的下载地址:http://gtk.php.net/download.php?language=en-US, 猿哥选择了最新版本(beta版),可能有人会问我们为啥不选最新的stable版 ...
- Canvas游戏计算机图形教程
TechbrooD 主站 WOW 登录 注册 0首页 1简介 1.1WWW 技术变迁和生态 1.2WWW 学习建议 1.3WWW 互联网基础知识 1.4WWW Web 1.5 WWW Web ...
- 面向对象设计模式纵横谈:Factory Method 工厂方法模式(笔记记录)
从耦合关系谈起 耦合关系直接决定着软件面对变化时的行为 -模块与模块之间的紧耦合使得软件面对变化时,相关模块都要随之更改 -模块与模块之间的松耦合使得软件面对变化时,一些模块更容易被替换或者更改,但其 ...
- Java图形化界面设计——布局管理器之GridBagLayout
GridBagLayout 不会随着窗口的变化标签随之发生变化,可固定. ---------------------------------------------------------- impo ...
- 16进制string转成int
http://blog.csdn.net/wl1524520/article/details/25706521
- Java WebService 教程系列之 Spring 整合 CXF
Java WebService 教程系列之 Spring 整合 CXF 一.引入 jar 包 <dependency> <groupId>org.apache.cxf</ ...