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

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

利用双向链表模拟

 #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. static NSString *ID的改进

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPa ...

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

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

  3. Java统计数据库表中记录数

    public static int count(String txyl_table) {// 获取用户数量 int i = 0;// Store_Information Connection con ...

  4. How can I style a JavaFX SplitMenuButton in CSS

    0 down vote favorite I try to style a SplitMenuButton in JavaFX. I've got a menuButton and a SplitMe ...

  5. C/C++中的getline函数总结:

    来自:http://www.cnblogs.com/xFreedom/archive/2011/05/16/2048037.html C/C++中的getline函数总结 getline函数是一个比较 ...

  6. R与JAVA的整合

    R是统计计算的强大工具,而JAVA是做应用系统的主流语言,两者天然具有整合的需要.关于整合,一方面,R中可以创建JAVA对象调用JAVA方法,另一方面,JAVA中可以转换R的数据类型调用R的函数,互相 ...

  7. Antenna Placement(匈牙利算法 ,最少路径覆盖)

    Antenna Placement Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6991   Accepted: 3466 ...

  8. poj1094

    Sorting It All Out Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 29539   Accepted: 10 ...

  9. python 之验证码

    验证码原理在于后台自动创建一张带有随机内容的图片,然后将内容通过img标签输出到页面. 安装图像处理模块: pip3 install pillow

  10. nginx lua处理图片

    user apache apache; worker_processes 4; worker_rlimit_nofile 100000; #error_log logs/error.log; #err ...