zoukankan      html  css  js  c++  java
  • hdu 3183 贪心

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

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

    利用双向链表模拟

     1 #include<cstdio>
     2 #include<iostream>
     3 #include<algorithm>
     4 #include<cstring>
     5 #include<cmath>
     6 #include<queue>
     7 using namespace std;
     8 const int maxn=1005;
     9 int n,m,t;
    10 char s[maxn];
    11 struct Node
    12 {
    13     int v;
    14     int from,to;
    15     void input(char val,int i)
    16     {
    17         v=val-'0';
    18         from=i-1;
    19         to=i+1;
    20     }
    21 }node[maxn];
    22 void del(int t)
    23 {
    24     int temp=node[t].from;
    25     node[temp].to=node[t].to;
    26     node[node[t].to].from=temp;
    27 }
    28 int main()
    29 {
    30     int i,j,k;
    31     #ifndef ONLINE_JUDGE
    32     freopen("1.in","r",stdin);
    33     #endif
    34     while(scanf("%s%d",&s,&m)!=EOF)
    35     {
    36         int n=strlen(s);
    37         for(i=1;i<=n;i++)
    38         {
    39             node[i].input(s[i-1],i);
    40         }
    41         node[0].to=1;
    42         node[n+1].from=n;
    43         int t=0;
    44         while(m--)
    45         {
    46             while(node[t].to!=n+1&&node[node[t].to].v>=node[t].v) t=node[t].to;
    47             del(t);
    48             t=node[t].from;
    49         }
    50         t=node[0].to;
    51         while(t!=n+1 && node[t].v==0)t=node[t].to;
    52         if(t==n+1)
    53         {
    54             printf("0
    ");
    55             continue;
    56         }
    57         while(t!=n+1)
    58         {
    59             printf("%d",node[t].v);
    60             t=node[t].to;
    61         }
    62         printf("
    ");
    63     }
    64 }
  • 相关阅读:
    Droppable(放置)组件
    Draggable(拖动)组件
    1.引入必要的文件 2.加载 UI 组件的方式 4.Parser 解析器
    mvc自带的异步表单提交
    MVC,jquery异步
    Container With Most Water
    Palindrome Number
    String to Integer (atoi)
    Merge k Sorted Lists
    Longest Valid Parentheses
  • 原文地址:https://www.cnblogs.com/cnblogs321114287/p/4364273.html
Copyright © 2011-2022 走看看