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[];
const int inf=0x3f3f3f3f;
const ll infll = 0x3f3f3f3f3f3f3f3fLL;
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
inline void P(int x)
{
Num=;if(!x){putchar('');puts("");return;}
while(x>)CH[++Num]=x%,x/=;
while(Num)putchar(CH[Num--]+);
puts("");
}
//************************************************************************************** ll dp[maxn];
void solve()
{
ll n,m,a,sum=,ans=;
n=read(),m=read();
for(int i=;i<n;i++)
{
a=read();
if(i>=m)sum-=dp[i-m];
dp[i]=;
if(a>sum)
{
ans+=a-sum;
dp[i]=a-sum;
sum=a;
}
}
cout<<ans<<endl;
}
int main()
{
//test;
int t=read();
for(int cas=;cas<=t;cas++)
{
printf("Case #%d: ",cas);
solve();
}
}
cdoj 04 Complete Building the Houses 暴力的更多相关文章
- UESTC 1817 Complete Building the Houses
Complete Building the Houses Time Limit: 2000MS Memory Limit: 65535KB 64bit IO Format: %lld & %l ...
- CDOJ 1292 卿学姐种花 暴力 分块 线段树
卿学姐种花 题目连接: http://acm.uestc.edu.cn/#/problem/show/1292 Description 众所周知,在喵哈哈村,有一个温柔善良的卿学姐. 卿学姐喜欢和她一 ...
- HAUT--1262--魔法宝石(暴力)
1262: 魔法宝石 时间限制: 2 秒 内存限制: 64 MB提交: 525 解决: 157提交 状态 题目描述 小s想要创造n种魔法宝石.小s可以用ai的魔力值创造一棵第i种魔法宝石,或是使用 ...
- 原始启动log&新log
root@Taiyear:/# U-Boot 1.1.3 (Dec 27 2013 - 09:14:28) SoC:MediaTek MT7620 DRAM: Memory Testing..655 ...
- 转:分享13款PHP开发框架
文章来自于:http://mashable.com/2014/04/04/php-frameworks-build-applications/ Building software applicatio ...
- LS1021ATWR开发板启动日志分析
一.背景 LS1021ATWR开发板运行官方的openwrt系统 二.日志分析 2.1 linux相关日志 root@OpenWrt:/# reboot 重启 root@OpenWrt:/# [ 2 ...
- FIR300M刷openwrt
淘宝看到一款FIR300M路由器,当时只要19.9元.图便宜就买了. Hardware Architecture: MIPS Vendor: MediaTek (Ralink) Bootloader: ...
- win10下pip3安装tesserocr时报错
使用pip3在线安装tesserocr时报错,刚开始报错内容是提示未安装vs2014,安装完以后报错内容如下 ERROR: Command errored out with exit status 1 ...
- MINIX3 保护模式分析
3.1 INTEL 保护模式概要 先要说明一个问题:不是 MINIX3 一定要设置这个保护模式,但是在 386 平台上, 引入了这个保护模式机制,MINIX3 不得不设立相关保护模式的内容.由于 38 ...
随机推荐
- Worm
Description 自从见识了平安夜苹果的涨价后,Lele就在他家门口水平种了一排苹果树,共有N棵. 突然Lele发现在左起第P棵树上(从1开始计数)有一条毛毛虫.为了看到毛毛虫变蝴蝶的过程,Le ...
- javascript针对DOM的应用
所谓针对DOM的应用.也就我这里只教大家用javascript操作页面中dom元素做交互.我相信可能大部分人来这里学javascript主要还是想用这个结合页面中的DOM元素做一些实际有用的交互效果. ...
- IOS-简单计时器的使用
1. 使用NSTimer *_timer --游戏计时器 2. NSDate *_startTime -- 开始时间 3. 初始化计时器 _timer = [NSTimer scheduledTime ...
- 坑爹的gltools编译错误解决
搭边手游,看opengl superbible, 书中代码需要一个gltools库.作者自己提供的code google地址里gltools项目是空的,此一坑. 他的网站(www.starstones ...
- C语言实现strcpy
strcpy.h: #ifndef STRCPY_H #define STRCPY_H #include <stdio.h> char *cat_strcpy(char *dst, con ...
- 【C#】Abstract和Virtual的区别
一.Virtual方法(虚方法) virtual 关键字用于在基类中修饰方法.virtual的使用会有两种情况: 情况1:在基类中定义了virtual方法,但在派生类中没有重写该虚方法.那么在对派生类 ...
- 【转】What's the difference between simulation and emulation
摘要:这2个单词 还是用英文解释,比较准确.按我的理解:simulation就是模拟,可以做些改变. emulation是仿真,是按照原来的样子进行部署,不可以改变. Yes, the concept ...
- Hadoop学习记录(1)|伪分布安装
本文转载自向着梦想奋斗博客 Hadoop是什么? 适合大数据的分布式存储于计算平台 不适用小规模数据 作者:Doug Cutting 受Google三篇论文的启发 Hadoop核心项目 HDFS(Ha ...
- hdu5514-Frogs(容斥原理)好题
题意:有m个石头围成一圈,编号分别为0到m-1,现在有n只青蛙,都在0号石头上,第i只青蛙会从当前编号为p的石头跳到编号为(p+ai)%m的石头上.被青蛙经过的石头都会被占领,求这m块石头中所有被占领 ...
- 一个效果很华丽的仿桌面APP,却胜似Launcher
开发Android APP的同学是否对于Launcher实现的绚丽效果而痴迷呢?什么,连Android Launcher是什么都不知道.好吧,拿起侬的手机,在解锁后的首页界面上左右滑动滑动,体验体验, ...