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 ...
随机推荐
- Delphi 串口通信数据位长度对传输数据的影响 转
针对串口通信,关于设置数据位长度对通信的影响,如图: 在串口数据通信中,会看到串口参数设置.其中“数据位”设置,共有四档选项,分别是8.7.6.5.那么改变这个参数会对数据的传输有什么影响呢? 我 ...
- CMDB反思4
CMDB模型设计2 http://blog.vsharing.com/xqscool/A1275233.html 估计大家看到破子的这两篇都有点晕哈,我也有点晕. 两篇对比来看. 第1处,属性部分 ...
- QS之warning message
Multiple message categories are specified as a comma separated list.
- MySQL 插入与自增主键值相等的字段 与 高并发下保证数据准确的实验
场景描述: 表t2 中 有 自增主键 id 和 字段v 当插入记录的时候 要求 v与id 的值相等(按理来说这样的字段是需要拆表的,但是业务场景是 只有某些行相等 ) 在网上搜的一种办法是 先获取 ...
- 使用arm开发板搭建无线mesh网络(一)
由于项目的需要,老板让我使用arm开发板(友善之臂的tiny6410)搭建无线mesh网络.一般而言,无线自组织网络的网络设备都是由用户的终端设备来充当,这些终端设备既要处理用户的应用数据,比如娱乐, ...
- pybombs 安装
参考:https://github.com/gnuradio/pybombs 先装:pip 然后: pip install PyBOMBS 更新源: pybombs recipes add gr-re ...
- 如何开启php报错
今天碰到一个很二的问题,安装了php网站之后,发现nginx一直无法解析到index.php文件,显示为空白,从后台的日志来看是500错误,但是同目录下的phpinfo.php却可以正常解析.想来应该 ...
- NServiceBus-容器
NServiceBus自动注册以及用户实现其所有组件处理程序和传奇,这样所有实例化模式和连接在默认情况下都是正确的,没有错误. NServiceBus在容器构建(目前Autofac的ilmerge版本 ...
- phonegap 新窗口 WebView
自定义WebView窗口打开 import com.ap.work.QuickWeb public class QuickPlugin extends CordovaPlugin { /** * 新开 ...
- gradle 及 git 环境下利用hook及gradle脚本自动添加versioncode和versionname的方法
在 app/build.gradle 文件里添加几行代码: def gitCommitShortHash = 'git log -1 --pretty=%h'.execute([], project. ...