zoukankan      html  css  js  c++  java
  • UESTC 1817 Complete Building the Houses

     

    Time Limit: 2000MSMemory Limit: 65535KB64bit IO Format: %lld & %llu

    [Submit]   [Go Back]   [Status]  

    Description

    Bear has a large, empty ground for him to build a home. He decides to build a row of houses, one after another, say n in total.

    The houses are designed with different height. Bear has m workers in total, and the workers must work side by side. So at a time bear can choose some continuous houses, no more than m, and add their heights by one, this takes one day to finish.

    Given the designed height for each house, what is the minimum number of days after which all the houses’ heights are no less than the original design?

    Input

    The first line of input contains a number T, indicating the number of test cases. (T<=50)

    For each case, the first line contains two integers n and m: the number of houses and the number of workers. The next line comes with n non-negative numbers, they are the heights of the houses from left to right. (1<=n, m<=100,000, each number will be less than 1,000,000,000)

    Output

    For each case, output “Case #i: “ first. (i is the number of the test case, from 1 to T). Then output the days when bear’s home can be built.

    Sample Input

    2
    3 3
    1 2 3
    3 3
    3 2 1

    Sample Output

    Case #1: 3
    Case #2: 3

    Source

    [Submit]   [Go Back]   [Status]  




    #include <iostream>
    #include <cstdio>
    #include <cstring>

    using namespace std;

    int sum[110000];
    long long int ans=0,d;

    int main()
    {
        int T,m,n,cas=1;
        scanf("%d",&T);
        while(T--)
        {
            ans=0;  int t;
            scanf("%d%d",&n,&m);
            memset(sum,0,sizeof(sum));
            for(int i=0;i<n;i++)
            {
                scanf("%d",&t);
                if(i-1>=0) sum+=sum[i-1];
                if(t-sum>0)
                {
                    d=t-sum;
                    sum+=d;
                    ans+=d;
                    if(i+m<n)
                    {
                        sum[i+m]-=d;
                    }
                }
            }
            printf("Case #%d: %lld ",cas++,ans);
        }
        return 0;
    }
    * This source code was highlighted by YcdoiT. ( style: Codeblocks )
  • 相关阅读:
    css绘制各种图形,三角形,长方形,梯形
    函数中,对形参做不加var的全局溢出赋值,可改变形参所指向的实参的本身值
    求数组中最大值,最小值
    placeholder 效果的实现,input提示字,获取焦点时消失
    js里apply用法
    jquery.lazyload.js-v1.9.1延时加载插件,已兼容ie6和各大浏览器
    移动端 元素外面使用伪类after加边框 导致其内部元素无法选中
    element组件知识点总结
    常用样式总结
    深入理解iframe
  • 原文地址:https://www.cnblogs.com/CKboss/p/3350879.html
Copyright © 2011-2022 走看看