UESTC 1817 Complete Building the Houses 贪心

同是比赛时候的一道水题,比赛的时候以为满层的就不能继续建了,没想到可以忽视它……

搞清题意后,唯一要注意的一点就是ans是long long的

/*
author:jxy
lang:C/C++
university:China,Xidian University
**If you need to reprint,please indicate the source**
*/
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <queue>
#define INF 1E9
using namespace std;
int a[1000001];
long long ans=0;
int main()
{
    int now;
    int T,C=0;
    int n,m,i,t;
    scanf("%d",&T);
    while(T--)
    {
        ans=now=0;
        scanf("%d%d",&n,&m);
        for(i=0;i<n;i++)
        {
            scanf("%d",&t);
            if(now>=t)
                a[i]=0;
            else
            {
                a[i]=t-now;
                ans+=a[i];
                now=t;
            }
            if(i+1-m>=0)//超过m长度
                now-=a[i+1-m];
        }
        printf("Case #%d: %lld\n",++C,ans);
    }
}
时间: 2024-12-22 15:46:48

UESTC 1817 Complete Building the Houses 贪心的相关文章

创建自定义模板 Building Custom Templates

创建|模板 December 23, 2002Using and Building Query Analyzer TemplatesBy Gregory A. Larsen Building Custom TemplatesBy now you should be somewhat familiar with using pre-existing templates to build your SQL code. It is now time to look at how you can lev

Spring Boot 项目构建 之 使用 Spring Boot 构建应用(Building an Application with Spring Boot)

Table of contents What you'll build What you'll need How to complete this guide Build with Gradle Build with Maven Build with Spring Tool Suite Learn what you can do with Spring Boot Create a simple web application Create an Application class Run the

Building a RESTful Web Service(转)

Building a RESTful Web Service This guide walks you through the process of creating a "hello world" RESTful web service with Spring. What you'll build You'll build a service that will accept HTTP GET requests at: http://localhost:8080/greeting a

Spring Boot 项目构建 之 使用 Gradle 构建 Java 项目(Building Java Projects with Gradle)

Table of contents What you'll build What you'll need How to complete this guide Set up the project Install Gradle Find out what Gradle can do Build Java code Declare dependencies Build your project with Gradle Wrapper Summary Tags gradle Concepts and

Building and deploying a basic WDF Kernel Mode Driver

Building and deploying a basic WDF Kernel Mode Driver Introduction At the end of December 2005, Microsoft released the new Windows Driver Foundation. This is a new framework for building Windows device drivers. It is a lot more high level than the Wi

UVa 11729 - Commando War(贪心)

"Waiting for orders we held in the wood, word from the front never came By evening the sound of the gunfire was miles away Ah softly we moved through the shadows, slip away through the trees Crossing their lines in the mists in the fields on our hand

A Complete Tutorial on Tree Based Modeling from Scratch (in R &amp; Python)

  A Complete Tutorial on Tree Based Modeling from Scratch (in R & Python)   MACHINE LEARNING PYTHON R   SHARE      MANISH SARASWAT , APRIL 12, 2016 / 52     Introduction Tree based learning algorithms are considered to be one of the best and mostly u

服务器磁盘扩展卷时遭遇“There is not enough space available on the disk(s) to complete this operation.”错误

在ESX VM的一台服务器由于磁盘空间告警,打算决定给E盘扩展空间,增加20G的空间,在操作过程遭遇了Expanding Disk Volume gives error "There is not enough space available on the disk(s) to complete this operation."错误.具体步骤如下   Step 1:   Step 2:   Step 3:   Step 4:             使用dispart命令查看时,也是如

c++-贪心法 区间完全覆盖问题

问题描述 贪心法 区间完全覆盖问题 50C 给定一个长度为m的区间~再给出n条用闭区间表示的线段~用贪心法求出最少的线段能覆盖完m区间~例: 区间长度8,可选的覆盖线段[26][14][36][37][68][24][35] 现需要代码 c++的 过程 : 1将每一个区间按照左端点递增顺序排列,拍完序后为[14],[24],[26],[35],[36],[37],[68] 2设置一个变量表示已经覆盖到的区域.再剩下的线段中找出所有左端点小于等于当前已经覆盖到的区域的右端点的线段中,右端点最大的线