zoukankan      html  css  js  c++  java
  • codeforces 677A A. Vanya and Fence(水题)

    题目链接:

    A. Vanya and Fence

    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Vanya and his friends are walking along the fence of height h and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed h. If the height of some person is greater than h he can bend down and then he surely won't be noticed by the guard. The height of the i-th person is equal to ai.

    Consider the width of the person walking as usual to be equal to 1, while the width of the bent person is equal to 2. Friends want to talk to each other while walking, so they would like to walk in a single row. What is the minimum width of the road, such that friends can walk in a row and remain unattended by the guard?

     
    Input
     

    The first line of the input contains two integers n and h (1 ≤ n ≤ 1000, 1 ≤ h ≤ 1000) — the number of friends and the height of the fence, respectively.

    The second line contains n integers ai (1 ≤ ai ≤ 2h), the i-th of them is equal to the height of the i-th person.

     
    Output
     

    Print a single integer — the minimum possible valid width of the road.

     
    Examples
     
    input
    3 7
    4 5 14
    output
    4
    input
    6 1
    1 1 1 1 1 1
    output
    6
    input
    6 5
    7 6 8 9 10 5
    output
    11

    题意:

    比h高的人宽为2,否则为1,求总的宽度;

    思路:

    水题一个;

    AC代码:
    #include <bits/stdc++.h>
    /*#include <vector>
    #include <iostream>
    #include <queue>
    #include <cmath>
    #include <map>
    #include <cstring>
    #include <algorithm>
    #include <cstdio>
    */
    using namespace std;
    #define Riep(n) for(int i=1;i<=n;i++)
    #define Riop(n) for(int i=0;i<n;i++)
    #define Rjep(n) for(int j=1;j<=n;j++)
    #define Rjop(n) for(int j=0;j<n;j++)
    #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 LL inf=1e10;
    const int N=1e5+15;

    int n,h;
    int a[2000];
    int main()
    {
    read(n);
    read(h);
    int sum=0;
    Riep(n)
    {
        read(a[i]);
        if(a[i]>h)sum+=2;
        else sum++;
    }
    print(sum);
        return 0;
    }
  • 相关阅读:
    聊聊ASP.NET Core默认提供的这个跨平台的服务器——KestrelServer[转]
    java的war包和jar包的区别
    shell编程中的表达式(-d, -f, -L 等)
    nginx 403 forbidden
    docker删除镜像
    TCP的拥塞控制
    文件从暂存区撤销
    charles修改返回结果的4种方法
    LED 正负极区分
    病毒传播模拟游戏制作日志(三)
  • 原文地址:https://www.cnblogs.com/zhangchengc919/p/5551891.html
Copyright © 2011-2022 走看看