题意:给一个数字,删掉其中的若干位,使得最后的数字最小

就是每次删除数的时候都是删掉第一个比右边数大的数

利用双向链表模拟

 #include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
using namespace std;
const int maxn=;
int n,m,t;
char s[maxn];
struct Node
{
int v;
int from,to;
void input(char val,int i)
{
v=val-'';
from=i-;
to=i+;
}
}node[maxn];
void del(int t)
{
int temp=node[t].from;
node[temp].to=node[t].to;
node[node[t].to].from=temp;
}
int main()
{
int i,j,k;
#ifndef ONLINE_JUDGE
freopen("1.in","r",stdin);
#endif
while(scanf("%s%d",&s,&m)!=EOF)
{
int n=strlen(s);
for(i=;i<=n;i++)
{
node[i].input(s[i-],i);
}
node[].to=;
node[n+].from=n;
int t=;
while(m--)
{
while(node[t].to!=n+&&node[node[t].to].v>=node[t].v) t=node[t].to;
del(t);
t=node[t].from;
}
t=node[].to;
while(t!=n+ && node[t].v==)t=node[t].to;
if(t==n+)
{
printf("0\n");
continue;
}
while(t!=n+)
{
printf("%d",node[t].v);
t=node[t].to;
}
printf("\n");
}
}

hdu 3183 贪心的更多相关文章

  1. hdu 3183 A Magic Lamp(RMQ)

    题目链接:hdu 3183 A Magic Lamp 题目大意:给定一个字符串,然后最多删除K个.使得剩下的组成的数值最小. 解题思路:问题等价与取N-M个数.每次取的时候保证后面能取的个数足够,而且 ...

  2. hdu 3183 A Magic Lamp RMQ ST 坐标最小值

    hdu 3183 A Magic Lamp RMQ ST 坐标最小值 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3183 题目大意: 从给定的串中挑 ...

  3. HDU 3183.A Magic Lamp-区间找最小值-RMQ(ST)

    A Magic Lamp Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

  4. hdu 3183(贪心)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3183 思路:比较前后两个相邻的字符,如果前面一个字符大于后面一个字符,就把它去掉. #include ...

  5. 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 ...

  6. hdu 3183 A Magic Lamp 贪心

    #include <stdio.h> #include <string.h> #include <iostream> #include <algorithm& ...

  7. HDU 3183 - A Magic Lamp - [RMQ][ST算法]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3183 Problem DescriptionKiki likes traveling. One day ...

  8. Hdu 5289-Assignment 贪心,ST表

    题目: http://acm.hdu.edu.cn/showproblem.php?pid=5289 Assignment Time Limit: 4000/2000 MS (Java/Others) ...

  9. hdu 4803 贪心/思维题

    http://acm.hdu.edu.cn/showproblem.php?pid=4803 话说C++还卡精度么?  G++  AC  C++ WA 我自己的贪心策略错了 -- 就是尽量下键,然后上 ...

随机推荐

  1. ios 随机色 宏定义

    #define RGBColor(r, g, b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1] #d ...

  2. Java Base64、AES、SHA1、MD5加密算法

    package com.example.decript; import java.io.UnsupportedEncodingException; import java.security.Inval ...

  3. Kali实现局域网ARP欺骗和ARP攻击

    原文地址: http://netsecurity.51cto.com/art/201303/386031.htm http://xiao106347.blog.163.com/blog/static/ ...

  4. centos 搭建gitlab

    #修改yum源 yum -y install wget cd /etc/yum.repos.d wget -O CentOS-Base.repo http://mirrors.aliyun.com/r ...

  5. ecshop 在php5.5上安装错误解决

    1.找到ecshop\includes\cls_image.php文件 搜索 function gd_version 改成 static function gd_version 2.Strict St ...

  6. DROP TABLE ** CASCADE CONSTRAINTS PURGE删除表的时候级联删除从表外键

    1.关于 cascade constraints 假设A为主表(既含有某一主键的表),B为从表(即引用了A的主键作为外键). 则当删除A表时,如不特殊说明,则 drop table A 系统会出现错误 ...

  7. SSN 社会安全号码

    SSN是 Social Security Number 的缩写,译为「社会安全号码」,为美国社会安全卡(Social Security Card)上的 9 位数字.SSN 原本目的是用于追踪个人的纳税 ...

  8. linux用命令行来执行php程序

    <?php $start = microtime(true); for($i=0 ; $i <10000 ; $i ++){ // echo '正在执行第'.$i.'个操作! '.PHP_ ...

  9. centOS6.4 extundelete工具恢复rm -rf 删除的目录

    PS:补充下,我在fedora 19上运行的时候遇到的一个问题: [root@localhost extundelete-]# ./configure Configuring extundelete ...

  10. Asp.net面试题

    Asp.net核心技术思想 1.概述反射和序列化 反射:程序集包含模块,而模块包含类型,类型又包含成员.反射则提供了封装程序集.模块和类型的对象.您可以使用反射动态地创建类型的实例,将类型绑定到现有对 ...