TOJ 4493 Remove Digits 贪心
4493: Remove Digits
Description
Given an N-digit number, you should remove K digits and make the new integer as large as possible.
Input
The first line has two integers N and K (N不大于500000).
The next line has a N-digit number with no leading zero.
Output
Output the largest possible integers by removing K digits.
Sample Input
4 2
2835
Sample Output
85
在一个字符串里找到n-k位的递减数列or前几位递减,一直超时。。。
贪心用栈实现就好的
#include <stdio.h>
char s[];
int main()
{
int n,k,i,j,f=;
s[]=;
scanf("%d%d",&n,&k);
getchar();
for(i=; i<n; i++)
{
char c;
c=getchar();
while(c>s[f])
{
if(!k||!f)break;
k--;
f--;
}
s[++f]=c;
}
f-=k;
s[++f]=;
printf("%s",s+);
return ;
}
TOJ 4493 Remove Digits 贪心的更多相关文章
- TZOJ 4493: Remove Digits
4493: Remove Digits 时间限制(普通/Java):1000MS/3000MS 内存限制:65536KByte 总提交: 329 测试通过:77 描述 G ...
- 【TOJ 4493】Remove Digits(单调栈贪心)
描述 Given an N-digit number, you should remove K digits and make the new integer as large as possible ...
- uva 993 Product of digits (贪心 + 分解因子)
Product of digits For a given non-negative integer number N , find the minimal natural Q such tha ...
- Codeforces 509C Sums of Digits 贪心
这道题目有人用DFS.有人用DP 我觉得还是最简单的贪心解决也是不错的选择. Ok,不废话了,这道题目的意思就是 原先存在一个严格递增的Arrary_A,然后Array_A[i] 的每位之和为Arra ...
- Codeforces Round #667 (Div. 3) D. Decrease the Sum of Digits (贪心)
题意:给你一个正整数\(n\),每次可以对\(n\)加一,问最少操作多少次是的\(n\)的所有位数之和不大于\(s\). 题解:\(n\)的某个位置上的数进位,意味这后面的位置都可以被更新为\(0\) ...
- (Problem 37)Truncatable primes
The number 3797 has an interesting property. Being prime itself, it is possible to continuously remo ...
- codeforces 887A Div. 64 思维 模拟
A. Div. 64 time limit per test 1 second memory limit per test 256 megabytes input standard input out ...
- kettle--组件(2)--计算器
组件如下: 对计算类型的说明如下: The table below contains descriptions associated with the calculator step: Functio ...
- Codeforces Round #444 (Div. 2)A. Div. 64【进制思维】
A. Div. 64 time limit per test 1 second memory limit per test 256 megabytes input standard input out ...
随机推荐
- 【extjs6学习笔记】1.8 初始: ExtJS命名约定
Convention for Description Example Class 类名应该在CamelCase中 MyCustomClass 类名应包含字母数字字符. 如果属于技术术语,则允许使用数字 ...
- java object默认的基本方法
java object默认的基本方法中没有copy(),含有如下9个方法: getClass(), hashCode(), equals(), clone(), toString(), notify ...
- 【UML】时序图Sequence diagram(交互图)(转)
前言 UML时序图是UML动态图之一,它是强调时间顺序的交互图. 定义 时序图是显示按时间顺序排列的对象之间交互的图. 组成元素 对象 包括三种命名 ...
- centos7-httpd虚拟主机
Apache虚拟主机: 一台WEB服务器发布单个网站会非常浪费资源,所以一台WEB服务器上会发布多个网站, 在一台服务器上发布多网站,也称之为部署多个虚拟主机,WEB虚拟主机配置方法有三种: 基于单I ...
- MySQL-08 MySQL8.0新特性
性能 MySQL 8.0 在一定的用户访问条件下,速度要比 MySQL 5.7 快 2 倍.MySQL 8.0 在以下方面带来了更好的性能:读/写工作负载.IO 密集型工作负载.以及高竞争(" ...
- vue 报错unknown custom element解决方法
原因: 没有引入相关组件导致的 解决办法: 如果组件是按需引入的必须引入你当前用到的组件,否则会报错
- Tomcat:使用startup.bat启动tomcat遇到报错
问题:使用startup.bat启动tomcat的时候报错,按照网页上的办法都试了一遍,但是没有解决问题.命令窗口启动tomcat会一闪而过,然后退出. 解决:1 检查环境变量配置是否有问题: CAT ...
- APP上线碰到的问题:Non-public API usage
①.Non-public API usage:The app references non-public symbols in XXXX: _UICreateCGImageFromIOSurface ...
- 控件中添加的成员变量value和control的区别
control型变量是这个控件所属类的一个实例(对象)可以通过这个变量来对该控件进行一些设置.而value只是用来传递数据,不能对控件进行其它的操作.control型变量可以获得控件的实例,通过这个变 ...
- 一些恶搞人的c++程序
top1: 不停打开的cmd(磁盘操作系统) 代码如下: #include<windows.h> using namespace std; int main() { system(&quo ...