Problem 1853 Number Deletion

Accept: 80    Submit: 239

Time Limit: 1000 mSec    Memory Limit : 32768 KB

 Problem Description

Given you one n-digital positive integer a,After removing any of them k( k < n) digits, the remaining figures form a new positive integer according to the origin order. For a given n-digital positive integers a
and positive integer k. Now ask you to find a algorithm to minimize the remaining integer.

 Input

The first line contains one integer t, represents the number of test cases.

Then following t lines,each line contain two numbers a,k (0 < a < 10^1000, k is less than the length of a).

 Output

Output the mininum number after the deletion.(the number can not contain leading zero)">it means that we should ignore the leading zeros of the output number

 Sample Input

1178543 4

 Sample Output

13

题意:在一个数中,删除k个数,使得剩下的数最小。

思路:让高数位尽量小。于是就要从前向后扫,每次就删当前数前面,比自己大的数;

#include <iostream>
#include <stdio.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath> using namespace std;
int vis[2222];
int T;
char s[2222];
int k; int main()
{
scanf("%d",&T);
while(T--)
{
scanf("%s%d",s,&k);
int i=0,j=1;
int len=strlen(s);
memset(vis,0,sizeof vis); while(k && j<len)//保证留在前面的数尽量小。于是要删除每一个数前面比他大的
{
for(int t=i;t>=0;t--)//为什么从近到远删,697982 697543
{
if(!vis[t] && s[t]>s[j])
{
vis[t]=1;
k--;
}
if(k==0)break;
}
i=j;
j++;
} for(i=len-1;i>=0 && k;i--)//一遍扫完之后发现还没删到k个数。那么就要从后向前删。由于前面已经是最小的数字了,保证了从小到大的排列
{
if(vis[i]==0)
{
vis[i]=1;
k--;
}
if(k==0) break;
} int flag=0;
for(int i=0;i<len;i++)
{
if(vis[i])continue;
if(flag || s[i]!='0')
{
printf("%c",s[i]);
flag=1;
}
}
if(flag==0) puts("0");//假设所有删完了,那么就要输出0
else
puts(""); } return 0;
}

FZU Problem 1853 Number Deletion的更多相关文章

  1. FZu Problem 2233 ~APTX4869 (并查集 + sort)

    题目链接: FZu Problem 2233 ~APTX4869 题目描述: 给一个n*n的矩阵,(i, j)表示第 i 种材料 和 第 j 种材料的影响值,这个矩阵代表这n个物品之间的影响值.当把这 ...

  2. FZu Problem 2236 第十四个目标 (线段树 + dp)

    题目链接: FZu  Problem 2236 第十四个目标 题目描述: 给出一个n个数的序列,问这个序列内严格递增序列有多少个?不要求连续 解题思路: 又遇到了用线段树来优化dp的题目,线段树节点里 ...

  3. 翻翻棋(找规律问题)(FZU Problem 2230)

    题目是这样的: FZU Problem 2230 象棋翻翻棋(暗棋)中双方在4*8的格子中交战,有时候最后会只剩下帅和将.根据暗棋的规则,棋子只能上下左右移动,且相同的级别下,主动移动到地方棋子方将吃 ...

  4. fzu 2111 Min Number

      http://acm.fzu.edu.cn/problem.php?pid=2111  Problem 2111 Min Number Accept: 572    Submit: 1106Tim ...

  5. FZU Problem 2150 Fire Game

    Problem 2150 Fire Game Accept: 145    Submit: 542 Time Limit: 1000 mSec    Memory Limit : 32768 KB P ...

  6. FZU 1649 Prime number or not米勒拉宾大素数判定方法。

    C - Prime number or not Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%I64d & % ...

  7. fzu Problem 2148 Moon Game(几何 凸四多边形 叉积)

    题目:http://acm.fzu.edu.cn/problem.php?pid=2148 题意:给出n个点,判断可以组成多少个凸四边形. 思路: 因为n很小,所以直接暴力,判断是否为凸四边形的方法是 ...

  8. fzu Problem 2140 Forever 0.5(推理构造)

    题目:http://acm.fzu.edu.cn/problem.php?pid=2140 题意: 题目大意:给出n,要求找出n个点,满足: 1)任意两点间的距离不超过1: 2)每个点与(0,0)点的 ...

  9. Fzu Problem 2082 过路费 LCT,动态树

    题目:http://acm.fzu.edu.cn/problem.php?pid=2082 Problem 2082 过路费 Accept: 528    Submit: 1654Time Limit ...

随机推荐

  1. Linux - 网络相关指令

    系统时间与开关机 查看系统时间 date 查看硬件日期 hwclock 学习Linux不必全部指令都会,只要记住主要常用的几个就可以了.--MK 关机命令 shutdown init reboot p ...

  2. 备份SQL SERVER 2005数据库

  3. TCP心跳包

    所谓的心跳包就是客户端定时放送简单的信息给服务器端,告诉它我还在而已.代码就是每 隔几分钟发送一个固定信息给服务器端,服务器端回复一个固定信息.如果服务器端几分钟后没有收到客户端信息则视客户端断开.比 ...

  4. Cracking the Coding Interview 6.2

    There is an 8*8 chess board in which two diagnolly opposite corners have been cut off. You are given ...

  5. [XJOI]noip43 T2多人背包

    多人背包 DD 和好朋友们要去爬山啦!他们一共有 K 个人,每个人都会背一个包.这些包的容量是相同的,都是 V.可以装进背包里的一共有 N 种物品,每种物品都有给定的体积和价值.在 DD 看来,合理的 ...

  6. CI中的超级对象

    CI中的超级对象就是当前控制器对象,它提供了很多属性,可以通过var_dump($this)打印所有的超级对象: load可以理解为一个加载器,加载了很多功能,可以理解为当你使用 $this -> ...

  7. 修复lsp,360浏览器可以上网其它软件不行

    netsh winsock reset netsh int ip reset 重启电脑

  8. Struts2学习笔记 - Part.01

    1.关于Struts2中的struts.xml文件中action设置 <!-- 它是一个通用action,此处的*表明它可以处理任意的请求--> <action name=" ...

  9. python第三方模块大杂烩

    Python单元测试框架之pytest---如何执行测试用例 unittest单元测试框架实现参数化 (用例有相似参数断言时使用,可以精简代码) python中标示符作用详解 一篇文章让你彻底搞清楚P ...

  10. SVD分解.潜语义分析.PythonCode

    原文链接:http://www.cnblogs.com/appler/archive/2012/02/02/2335886.html 原始英文链接:http://www.puffinwarellc.c ...