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. js slider

      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.or ...

  2. firewalld使用

    1.firewalld的基本使用 启动: systemctl start firewalld 关闭: systemctl stop firewalld 查看状态: systemctl status f ...

  3. uirecorder录制脚本

    安装步骤不再描述. 将手机通过数据线连接到mac 然后输入启动macaca的命令: macaca server --port 4444 --verbose & 在输入 命令:uirecorde ...

  4. Super超级ERP系统---(7)货位管理

    货位是ERP系统总的仓库管理中必不可少的,仓库是有货架组成,货架上的每个格子就是一个货位,所有货位上的商品的库存总和就是仓库商品的库存.仓库的货位主要分为货架和托盘,货架就是仓库的固定货位,托盘就是移 ...

  5. website robots.txt 防爬虫 措施

    robots.txt文件用法举例: 1. 允许所有的robot访问 User-agent: * Allow: / 或者 User-agent: * Disallow: 2. 禁止所有搜索引擎访问网站的 ...

  6. TensorFlow-正弦函数拟合

    MNIST的代码还是有点复杂,一大半内容全在搞数据,看了半天全是一滩烂泥.最关键的是最后输出就是一个accuracy,我根本就不关心你准确率是0.98还是0.99好吗?我就想看到我手写一个5,你程序给 ...

  7. C++中内存分配、函数调用和返回值问题

    转载博客:http://blog.csdn.net/q_l_s/article/details/52176159(源地址找不到,就贴了这位大神的博客地址,他也是转载的,不过要是学习的话,他的博客很不错 ...

  8. UWP Tiles

    1.我们建议安装通知库 NuGet 程序包 详细内容 2.我们建议安装NotificationsVisualizerLibrary 这是 The official NotificationsVisua ...

  9. C#获取硬盘序列号

    //创建ManagementObjectSearcher对象 ManagementObjectSearcher searcher = new ManagementObjectSearcher(&quo ...

  10. 三维地图中的A*寻路

    跟二维地图原理一样,只不过搜索方向多了,二维只搜8个方向,而三维要搜26个方向. 不懂的看我以前写的文章,这里直接贴代码: #include <iostream> #include < ...