zoukankan      html  css  js  c++  java
  • 洛谷 P3078 [USACO13MAR]扑克牌型Poker Hands

    题目描述

    Bessie and her friends are playing a unique version of poker involving a deck with N (1 <= N <= 100,000) different ranks, conveniently numbered 1..N (a normal deck has N = 13). In this game, there is only one type of hand the cows can play: one may choose a card labeled i and a card labeled j and play one card of every value from i to j. This type of hand is called a "straight".

    Bessie's hand currently holds a_i cards of rank i (0 <= a_i <= 100000). Help her find the minimum number of hands she must play to get rid of all her cards.

    一个牛有N堆牌,每堆排数量不等。一只牛一次可以将第i张到第j张各打一张出去,问最少几次打完

    输入输出格式

    输入格式:

     

    * Line 1: The integer N.

    * Lines 2..1+N: Line i+1 contains the value of a_i.

     

    输出格式:

     

    * Line 1: The minimum number of straights Bessie must play to get rid of all her cards.

     

    输入输出样例

    输入样例#1: 复制
    5 
    2 
    4 
    1 
    2 
    3 
    
    输出样例#1: 复制
    6 
    

    说明

    Bessie can play a straight from 1 to 5, a straight from 1 to 2, a straight from 4 to 5, two straights from 2 to 2, and a straight from 5 to 5, for a total of 6 rounds necessary to get rid of all her cards.

    思路:贪心即可。

    #include<cstdio>
    #include<cstring>
    #include<iostream>
    #include<algorithm>
    using namespace std;
    int n;
    long long ans,x,pre;
    int main(){
        scanf("%d%lld",&n,&x);
        ans+=x;pre=x;
        for(int i=2;i<=n;i++){
            scanf("%lld",&x);
            if(x>pre)    ans+=x-pre;
            pre=x;
        }
        cout<<ans;
    }
    细雨斜风作晓寒。淡烟疏柳媚晴滩。入淮清洛渐漫漫。 雪沫乳花浮午盏,蓼茸蒿笋试春盘。人间有味是清欢。
  • 相关阅读:
    mysql:基础管理、体系结构、升级降级
    Linux网络基础
    mysql 忘记本地密码
    seq命令的用法
    mysql03-SQL应用
    SolidWorks 如何改变封闭草图的背景颜色
    新版 AD 无法选中某些部件(如 Via,Pad)的问题
    安装 dot net 时出现严重错误 0x80070643 安装时发生严重错误 1603 ndp48
    IO 口扩展
    自动波特率检测
  • 原文地址:https://www.cnblogs.com/cangT-Tlan/p/8834932.html
Copyright © 2011-2022 走看看