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);
    }
}


目录
相关文章
|
26天前
|
算法 安全 数据挖掘
文献解读-Transcriptional Start Site Coverage Analysis in Plasma Cell-Free DNA Reveals Disease Severity and Tissue Specificity of COVID-19 Patients
这项研究展示了 cfDNA 分析在揭示新冠肺炎进展中的组织参与情况和疾病机制方面的潜力。它强调了 cfDNA 作为无创生物标志物在疾病严重程度检测、患者监测和预后评估中的应用价值。这种方法为理解新冠肺炎的病理生理学提供了新的视角,并可能帮助开发更有针对性的治疗策略。
26 2
|
4月前
|
机器学习/深度学习 存储 开发框架
【博士每天一篇文献-算法】NICE Neurogenesis Inspired Contextual Encoding for Replay-free Class Incremental Learn
NICE(Neurogenesis Inspired Contextual Encoding)是一种新型深度神经网络架构,旨在通过模拟生物神经系统的成熟过程来解决类别增量学习中的灾难性遗忘问题,无需重放旧样本即可实现有效的增量学习。
61 5
ORB_SLAM2_CUDA : Make failed - Compiling examples - Undefined References
ORB_SLAM2_CUDA : Make failed - Compiling examples - Undefined References
110 0
PAT (Advanced Level) Practice - 1004 Counting Leaves(30 分)
PAT (Advanced Level) Practice - 1004 Counting Leaves(30 分)
114 0
PAT (Advanced Level) Practice - 1068 Find More Coins(30 分)
PAT (Advanced Level) Practice - 1068 Find More Coins(30 分)
117 0
PAT (Advanced Level) Practice - 1049 Counting Ones(30 分)
PAT (Advanced Level) Practice - 1049 Counting Ones(30 分)
121 0
PAT (Advanced Level) Practice - 1143 Lowest Common Ancestor(30 分)
PAT (Advanced Level) Practice - 1143 Lowest Common Ancestor(30 分)
123 0
|
存储 算法
PAT (Advanced Level) Practice - 1151 LCA in a Binary Tree(30 分)
PAT (Advanced Level) Practice - 1151 LCA in a Binary Tree(30 分)
129 0
PAT (Advanced Level) Practice - 1127 ZigZagging on a Tree(30 分)
PAT (Advanced Level) Practice - 1127 ZigZagging on a Tree(30 分)
125 0