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 ...
随机推荐
- 初识SeekBar
SeekBar拖动条,是Progress的间接子类 <SeekBar android:id="@+id/seekBar1" android:layout_width=&quo ...
- 如何对ABAP SE80 workbench做增强
流程如下: 要获取更多Jerry的原创文章,请关注公众号"汪子熙":
- QT5:介绍
一.简介 QT是一个跨平台的C++开发库,主要用来开发图形用户界面(Graphical User Interface,GUI) QT除了可以绘制漂亮的界面(包括控件/布局/交互),还可以多线程/访问数 ...
- 02_5if switch分支与循环语句
02_5if switch分支与循环语句 1.语句 1.1条件语句-根据不同条件,执行不同语句. if if ... else if ... else if if ... else if ... el ...
- linux 使用wget下载https连接地址cannot verify github.com's certificate
使用linux的wget下载时候会出现网站没有证书警告的问题, 例如下载git时,可以使用wget https://github.com/git/git/archive/v2.3.0.zip --no ...
- iOS应用架构谈-part1概述
当我们讨论客户端应用架构的时候,我们在讨论什么? 其实市面上大部分应用不外乎就是颠过来倒过去地做以下这些事情: --------------- --------------- ------------ ...
- Codeforces 517 #B
http://codeforces.com/contest/1072/problem/B 开始想的只有搜索,时间复杂度$O(4^n)$,明显有问题. 想了半个小时没有思路,然后想到了正难则反,就开始步 ...
- python2和python3中filter函数
在python2和python3中filter是不同的,其中在python2中filter返回的是一个list,可以直接使用 >>> a = [1,2,3,4,5,6,7] > ...
- Linux基础学习-使用vsftpd服务传输文件
使用vsftpd服务传输文件 1 安装vsftpd [root@qdlinux ~]# yum install vsftpd Loaded plugins: product-id, search-di ...
- MySQL如何复制一个表
MySQL如何复制一个表 1 复制 employee 表 => employee2 () create table employee2 like employee () insert into ...