zoukankan      html  css  js  c++  java
  • hdu-5777 domino(贪心)

    题目链接:

    domino

    Time Limit: 2000/1000 MS (Java/Others)   

     Memory Limit: 131072/131072 K (Java/Others)


    Problem Description
    Little White plays a game.There are n pieces of dominoes on the table in a row. He can choose a domino which hasn't fall down for at most k times, let it fall to the left or right. When a domino is toppled, it will knock down the erect domino. On the assumption that all of the tiles are fallen in the end, he can set the height of all dominoes, but he wants to minimize the sum of all dominoes height. The height of every domino is an integer and at least 1.
     
    Input
    The first line of input is an integer T ( 1T10)
    There are two lines of each test case.
    The first line has two integer n and k, respectively domino number and the number of opportunities.( 2k,n100000)
    The second line has n - 1 integers, the distance of adjacent domino d, 1d100000
     
    Output
    For each testcase, output of a line, the smallest sum of all dominoes height
     
    Sample Input
    1
    4 2
    2 3 4
     
    Sample Output
    9
     
    题意:
    给出n个牌的距离,现在要你推k次把这些牌都推到,问这些牌的高度和最小是多少;
     
    思路:
     
    贪心,距离排序后把前k-1个去除,然后剩下的就是一定要越过的距离了;
     
    AC代码:
     
    /************************************************ 
    ┆  ┏┓   ┏┓ ┆    
    ┆┏┛┻━━━┛┻┓ ┆ 
    ┆┃       ┃ ┆ 
    ┆┃   ━   ┃ ┆ 
    ┆┃ ┳┛ ┗┳ ┃ ┆ 
    ┆┃       ┃ ┆  
    ┆┃   ┻   ┃ ┆ 
    ┆┗━┓    ┏━┛ ┆ 
    ┆  ┃    ┃  ┆       
    ┆  ┃    ┗━━━┓ ┆ 
    ┆  ┃  AC代马   ┣┓┆ 
    ┆  ┃           ┏┛┆ 
    ┆  ┗┓┓┏━┳┓┏┛ ┆ 
    ┆   ┃┫┫ ┃┫┫ ┆ 
    ┆   ┗┻┛ ┗┻┛ ┆       
    ************************************************ */  
    
    
    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <cmath>
    #include <bits/stdc++.h>
    #include <stack>
    
    using namespace std;
    
    #define For(i,j,n) for(int i=j;i<=n;i++)
    #define mst(ss,b) memset(ss,b,sizeof(ss));
    
    typedef  long long LL;
    
    template<class T> void read(T&num) {
        char CH; bool F=false;
        for(CH=getchar();CH<'0'||CH>'9';F= CH=='-',CH=getchar());
        for(num=0;CH>='0'&&CH<='9';num=num*10+CH-'0',CH=getchar());
        F && (num=-num);
    }
    int stk[70], tp;
    template<class T> inline void print(T p) {
        if(!p) { puts("0"); return; }
        while(p) stk[++ tp] = p%10, p/=10;
        while(tp) putchar(stk[tp--] + '0');
        putchar('
    ');
    }
    
    const LL mod=1e9+7;
    const double PI=acos(-1.0);
    const int inf=1e9;
    const int N=1e5+10;
    const int maxn=(1<<8);
    const double eps=1e-8;
    
    int a[N];
    int cmp(int x,int y)
    {
        return x>y;
    }
    int main()
    {       
            int t;
            read(t);
            while(t--)
            {
                int n,k;
                read(n);read(k);
                For(i,1,n-1)read(a[i]);
                sort(a+1,a+n,cmp);
                LL ans=0;
                For(i,k,n-1) ans=ans+a[i]+1;
                if(k>n)ans=n;
                else ans=ans+k;
                cout<<ans<<"
    ";
            }
            return 0;
    }
    

      

  • 相关阅读:
    LeetCode121.买卖股票的最佳时机
    OpenFunction 应用系列之一: 以 Serverless 的方式实现 Kubernetes 日志告警
    KubeSphere 核心架构浅析
    云原生爱好者周刊:服务网格的困境与破局
    DG:11.2.0.4 RAC在线duplicate恢复DG
    ORA-17629: Cannot connect to the remote database server
    DG:RFS[8]: No standby redo logfiles created for thread 2
    U盘内容不显示?U盘有文件却看不见?
    【CSS】特殊符号content编码及作为字体图标使用方法
    Python中的if __name__ == '__main__'(转载)
  • 原文地址:https://www.cnblogs.com/zhangchengc919/p/5722151.html
Copyright © 2011-2022 走看看