zoukankan      html  css  js  c++  java
  • cdoj 04 Complete Building the Houses 暴力

    Complete Building the Houses

    Time Limit: 20 Sec  Memory Limit: 256 MB

    题目连接

    http://acm.uestc.edu.cn/#/problem/show/3

    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

    HINT

    题意

    你想修n栋房子,高度分别为a[i],你一次最多可以同时修m栋连在一起的房子,然后问你最少多久能修完这些房子

    题解:

    暴力做就好了,直接从最左边考虑然后搞搞搞就好了

    代码:

    //qscqesze
    #include <cstdio>
    #include <cmath>
    #include <cstring>
    #include <ctime>
    #include <iostream>
    #include <algorithm>
    #include <set>
    #include <vector>
    #include <sstream>
    #include <queue>
    #include <typeinfo>
    #include <fstream>
    #include <map>
    #include <stack>
    typedef long long ll;
    using namespace std;
    //freopen("D.in","r",stdin);
    //freopen("D.out","w",stdout);
    #define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
    #define test freopen("test.txt","r",stdin)  
    #define maxn 200000
    #define mod 10007
    #define eps 1e-9
    int Num;
    char CH[20];
    const int inf=0x3f3f3f3f;
    const ll infll = 0x3f3f3f3f3f3f3f3fLL;
    inline ll read()
    {
        ll x=0,f=1;char ch=getchar();
        while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
        while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
        return x*f;
    }
    inline void P(int x)
    {
        Num=0;if(!x){putchar('0');puts("");return;}
        while(x>0)CH[++Num]=x%10,x/=10;
        while(Num)putchar(CH[Num--]+48);
        puts("");
    }
    //**************************************************************************************
    
    ll dp[maxn];
    void solve()
    {
        ll n,m,a,sum=0,ans=0;
        n=read(),m=read();
        for(int i=0;i<n;i++)
        {
            a=read();
            if(i>=m)sum-=dp[i-m];
            dp[i]=0;
            if(a>sum)
            {
                ans+=a-sum;
                dp[i]=a-sum;
                sum=a;
            }
        }
        cout<<ans<<endl;
    }
    int main()
    {
        //test;
        int t=read();
        for(int cas=1;cas<=t;cas++)
        {
            printf("Case #%d: ",cas);
            solve();
        }
    }
  • 相关阅读:
    「2019冬令营提高组」原样输出
    FJWC2019
    P2763 试题库问题
    P3979 遥远的国度
    P2754 [CTSC1999]家园
    P1251 餐巾计划问题
    P1382 楼房
    P1384 幸运数与排列
    P4294 [WC2008]游览计划
    P3345 [ZJOI2015]幻想乡战略游戏
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4544779.html
Copyright © 2011-2022 走看看