Codeforces677B

halcon3D 点云拟合球体 halon3D 点云拟合球面 阅读详情

http://codeforces.com/contest/677/problem/B

B. Vanya and Food Processor
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Vanya smashes potato in a vertical food processor. At each moment of time the height of the potato in the processor doesn't exceed h and the processor smashes k centimeters of potato each second. If there are less than k centimeters remaining, than during this second processor smashes all the remaining potato.

Vanya has n pieces of potato, the height of the i-th piece is equal to ai. He puts them in the food processor one by one starting from the piece number 1 and finishing with piece number n. Formally, each second the following happens:

  1. If there is at least one piece of potato remaining, Vanya puts them in the processor one by one, until there is not enough space for the next piece.
  2. Processor smashes k centimeters of potato (or just everything that is inside).

Provided the information about the parameter of the food processor and the size of each potato in a row, compute how long will it take for all the potato to become smashed.

Input

The first line of the input contains integers n, h and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ h ≤ 109) — the number of pieces of potato, the height of the food processor and the amount of potato being smashed each second, respectively.

The second line contains n integers ai (1 ≤ ai ≤ h) — the heights of the pieces.

Output

Print a single integer — the number of seconds required to smash all the potatoes following the process described in the problem statement.

Examples
Input
5 6 3
5 4 3 2 1
Output
5
Input
5 6 3
5 5 5 5 5
Output
10
Input
5 6 3
1 2 1 1 1
Output
2
Note

Consider the first sample.

  1. First Vanya puts the piece of potato of height 5 into processor. At the end of the second there is only amount of height 2 remaining inside.
  2. Now Vanya puts the piece of potato of height 4. At the end of the second there is amount of height 3 remaining.
  3. Vanya puts the piece of height 3 inside and again there are only 3 centimeters remaining at the end of this second.
  4. Vanya finally puts the pieces of height 2 and 1 inside. At the end of the second the height of potato in the processor is equal to 3.
  5. During this second processor finally smashes all the remaining potato and the process finishes.

In the second sample, Vanya puts the piece of height 5 inside and waits for 2 seconds while it is completely smashed. Then he repeats the same process for 4 other pieces. The total time is equal to 2·5 = 10 seconds.

In the third sample, Vanya simply puts all the potato inside the processor and waits 2 seconds.

题意:n个高度为 a[i] 的土豆,依次堆叠放进高度为 h 的粉碎桶,直到放不下了,开始粉碎,每秒粉碎 高度k 的土豆,问多少秒可以粉碎完所有土豆。


题解:如果直接模拟会超时,n=100,h=10^9,k=1, 每个a[i]=10^9, ans=10^11  ,数据超int,CF 必须用__int64.。所以优化就是每个a[i]加入桶之前就先对k取模,并记录下ans.最后的结果是一样的。


#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cctype>
#include<queue>
#include<cstdlib>
#include<string>
#include<cstdlib>
using namespace std;

#define LL __int64
#define maxn 100010
#define PI 3.1415926

LL ans;
int a[100005];
int main()
{
    int n,h,k,x;
    while(~scanf("%d%d%d",&n,&h,&k))
    {
        for(int i=0;i<n;i++)
        {
            scanf("%d",&a[i]);
        }
        x=0;
        ans=0;
        for(int i=0;i<n;i++)
        {
            if(x+a[i]>h)
            {
                x=0;
                ans++;
            }
            x+=a[i]%k;
            ans+=a[i]/k;
            if(x>=k)
            {
                x-=k;
                ans++;
            }
        }
        if(x!=0)
            ans+=1;
        printf("%I64d\n",ans);
    }
}


openbmc 支持mctp over pcie(二) 本文介绍了在OpenBMC系统中实现MCTP over PCIe的社区方案,主要针对AMD CPU和Intel CPU平台。方案基于社区开发的mctpd应用层和内核驱动,通过修改设备树(dts)配置内存区域,并编译Linux内核模块。验证时可通过查看/proc/net/protocols确认MCTP协议支持,使用ip addr命令检查mctppci0网络接口状态。相关代码和文档参考了AspeedTech和CodeConstruct的GitHub仓库。该方案为BMC作为MCTP端点提供了标准化实现方法。 阅读详情

相关推荐

别再只看pLDDT了!AlphaFold预测结果解读保姆级指南:pLDDT、PAE、pTM、ipTM到底怎么看?

本文详细解析了AlphaFold预测结果中的关键指标pLDDT、PAE、pTM和ipTM,帮助用户从单一依赖pLDDT进阶到全面理解蛋白质结构预测。通过实际案例和技巧,指导如何正确解读这些指标,避免常见错误,并提供了从预测到发表的实用建议。

weixin_29100399的博客 368

Codeforces 677B Vanya and Food Processor (模拟的好题)

B. Vanya and Food Processor time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Vanya smashes potato in a vertic

Pig_Me的博客 885

DDPG算法实战:用Python一步步实现深度强化学习中的连续动作控制

本文详细介绍了DDPG算法在深度强化学习中的连续动作控制应用,通过Python和PyTorch实现从零构建智能体。内容涵盖环境搭建、网络架构设计、经验回放、OU噪声实现及训练流程优化,帮助开发者掌握DDPG在机械臂控制等场景的核心技术。

weixin_30335575的博客 423

Codeforces Round #677 (Div. 3)A-G题解

Codeforces Round #677 (Div. 3)A-G题解 比赛链接:https://codeforces.ml/contest/1433/ A题 水,施行 题意为给定一个1到9999的每一位上数字相同的整数x,现在按照一定规则报数,问报到x的时候,总共报了多少位的数字。 报数规则为从1,11,111,1111到2,22,222,2222…到9,99,999,9999。 注意到我们需要关注的只是x是由哪个数字构成的,以及x有几位。 假设x是由若干个y构成的,对于任意的数字比如1,喊完1,11,1

StandNotAlone的博客 1780

编译原理实验二:LL(1)分析法(附C/C++完整代码)

本文讲述了LL(1)文法的原理及如何用C语言实现。并在给出的代码中实现了消除文法的左递归,First集,Follow集,select集的输出,构造预测分析表并输出,和对任意输入字符串的分析。程序总流程为:从文件读取文法 -> 输出文法信息 -> 消除左递归并输出消除后的文法 -> 计算First集并输出 -> 计算Follow集并输出 ->计算select集并输出 -> 判断是否是LL(1)文法 -> 构造预测分析表并输出 ->手动输入要分析的字符串 -> 输出分析过程和结果读取文件。

W_Wmwmwm的博客 6210

ESP32-BLE学习1-建立简单的server

start 学习之前,我想尝试使用ESP32的demo建立一个简单的server与手机接进行最基本的数据通信。 这里有BLE的简单讲解BLE资料 因为BLE的连接是具有主从机特性的,就像SPI,USB一些请求只能由主机端发起,连接也需要主机端发起。所以手机要想连上ESP32,就得将ESP32设置为从机模式。 从资料上可以看到,从机端通过Notify通知主机,所以从机就是GATT Server。 在进行ESP32 的demo学习之前,得大体看下ESP32的蓝牙组成,ESP32支持经典蓝牙和低功耗蓝牙4.2,

Spark的博客 1849

CodeForces 677B Vanya and Food Processor

#include<stdio.h> #include<string> #include<cstring> #include<queue> #include<algorithm> #include<functional> #include<vector> #include<iomanip> #include<math.h> #include<iostream> #include<sstream> #i

Katapeltes 425

PC网站实现微信扫码登录功能(二)

上篇我们介绍了怎么申请账号以及最后拿到appId和appSecret,如果有不清楚的可以看一下 PC网站实现微信扫码登录功能(一) 下面我就来说一下怎样在PC端怎么实现扫码登录功能。 一、进入官方文档网站 https://developers.weixin.qq.com/doc/oplatform/Website_App/WeChat_Login/Wechat_Login.html 其实官网对过程描述的已经非常细致了。并且提供了两种扫码方式。一种是跳转二维码扫描页面,另一种是内嵌式二维码。大家可以

qq_35771266的博客 3万+

B. Vanya and Food Processor【转】

B. Vanya and Food Processor time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Vanya smashes potato in a vertical ...

weixin_30617737的博客 161

【华为OD机试真题】65、高矮个子排队 | 机试真题+思路参考+代码解析 (C++、Java、Py、C语言、JS)

题目描述 >现在有一队小朋友,他们高矮不同,我们以正整数数组表示这一队小朋友的身高,如数组{5,3,1,2,3}。 >  我们现在希望小朋友排队,以"高" "矮" "高" "矮" 顺序排列,每一个高位置的小朋友要比相邻的位置高或者相等;每个 "矮" 位置的小朋友要比相邻的位置矮或者相等; >  要求小朋友们移动的距离和最小,第一个从“高"位开始排,输出最小移动距离即可。 >  例如,在示范小队{5,3,1,2,3}中, {5, 1, 3, 2, 3}是排序结果。 > 

KJ.JK 2113

Python数据可视化 Pyecharts 制作 Map 地图

大家好,我是Mr数据杨。想象一下,作为一名军师,如诸葛亮或郭嘉,'Map’就如同那战争的沙盘,兵马行动的轨迹,都需要准确的地图作为基础。‘基本设置’,就如同摆设这张战争沙盘,规定棋子的起始位置。‘数据配置选项’和’地图数据项’,就好比是军师们手中的情报,了解各路诸侯的兵力、粮草、地形等重要信息,以便于他们更好地布局。‘Demo’则代表着练兵之地,军师们可以在此基于已有数据,试验各种战术。

Mr数据杨 4万+

codeforces 677E

题意:给出一个1000*1000的举证,问你任意“十字乘积”的最大值。十字可以是#include using namespace std; #define N 2010 int d[N][N]; double s[8][N][N]; int p[8][N][N]; typedef long long LL; #define MOD 1000000007 //0,1 ,1,1, 1,0, 1

LFLONG的博客 405

CANFD加速是什么?和CANFD有什么区别?

在使用CAN设备上位机的时候,已经选择了CANFD,但还有一个选项是“CANFD加速”,那CANFD加速和不加速有什么区别呢?刚接触CANFD小伙伴肯定一脸懵,本篇主要是给大家分享一下他们的区别,如果对你有帮助,请转发,收藏,点赞💐🎉👍😊

汽车电子软件领域知识分享 1057

CodeForces 677B Vanya and Food Processor(打土豆,模拟)

http://codeforces.com/problemset/problem/677/B B. Vanya and Food Processor time limit per test 1 second memory limit per test 256 megabytes input standard input output s

Shyazhut 467

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

codeforces 677 B Vanya and Food Processor (模拟)

codeforces #355 B(Div 2)http://http://codeforces.com/contest/677/problem/B B. Vanya and Food Processor time limit per test 1 second memory limit per test 256 megabytes input standard input out

wchhlbt的博客 556

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

Codeforces 677B Vanya and Food Processor【模拟】

B. Vanya and Food Processor time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Vanya smashes potato in a vertical food pr

mengxiang000000 449

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

codeforces 677B Vanya and Food Processor(模拟)

思路:SB模拟... #include using namespace std; const int maxn = 1e5+7; int n; long long h,k,a[maxn]; int main() { scanf("%d%lld%lld",&n,&h,&k); for(int i=1;i<=n;i++) scanf("%d",&a[i]);

围巾的ACM博客 650

Codeforces 677 B.Coat of Anticubism【水题】

B. Coat of Anticubism time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output   As some of you know, cubism is a trend in a

mengxiang000000 664

[Codeforces677B]Vanya and Food Processor(模拟,数学)

题目链接:http://codeforces.com/contest/677/problem/B 题意:n个土豆,每个土豆高ai。现在有个加工机,最高能放h,每次能加工k。问需要多少次才能把土豆全加工完。 模拟就行了,加工次数用相除的结果,一个一个来会TLE 1 /* 2 ━━━━━┒ギリギリ♂ eye! 3 ┓┏┓┏┓┃キリキリ♂ mind! 4 ┛┗┛┗┛┃\○/ ...

weixin_30429201的博客 98

codeforces 677B B. Vanya and Food Processor(模拟)

题目链接: B. Vanya and Food Processor time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Vanya smashes potato in a vertica...

weixin_30258027的博客 100

B. Yet Another Bookshelf(思维)Codeforces Round #677 (Div. 3)

原题链接: https://codeforces.com/contest/1433/problem/B 测试样例 input 5 7 0 0 1 0 1 0 1 3 1 0 0 5 1 1 0 0 1 6 1 0 0 0 0 1 5 1 1 0 1 1 output 2 0 2 4 1 Note In the first test case of the example, you can shift the segment [3;3] to the right and the segment [4;

pursuit的博客 783

codeforces Round #677 (Div. 3) 1433B Yet Another Bookshelf

题目链接 题目翻译: 有一个能装n本书的书架。如果书架的第i个位置上有一本书,则ai=1,否则ai=0。题目保证书架上至少有一本书。 在一次移动中,你可以选择一段连续的区间[l;r],每个位置上都要有书(即对于任意i,l<=i<=r,ai=1都成立),然后: 将区间向右移动一个位置:对于所有的下标i(l<=i<=r),把下标为i的书移动到下标为i+1的位置。只有当r+1<=n并且下标为r+1的位置上没有书的时候才可以移动。 将区间向左移动一个位置:对于所有的下标i(l&lt

lmmmmmmmmmmmmmmm的博客 273

Codeforces Round #677 (Div. 3) B. Yet Another Bookshelf

题意: 书架上有很多书,1代表此位置有书,0没有书。每次可以抱一摞书移动一个格子。 (一摞书,多少都可以,连续的1视为一摞) 问最少多少次移动可以把所有的书归为一摞。 题解: 可以移动连续的书 所以答案就是1中间0的数量 双指针遍历即可 code: #include<bits/stdc++.h> //#pragma GCC optimize(2) #define rep(i,a,n) for (int i=a;i<=n;i++)//i为循环变量,a为初始值,n为界限值,递增 #defin.

sakuyu_10的博客 194

【CodeForces】Codeforces Round #677 (Div. 3) B. Yet Another Bookshelf (模拟&思维)

B. Yet Another Bookshelf time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output There is a bookshelf which can fit n books. The i-th position of bookshelf is ai=1 if there is a book on this position and ai=

黑桃 238

Codeforces Round #677 (Div. 3)A-G

Codeforces Round #677 (Div. 3) A. Boring Apartments 题意: 一个无聊的人喜欢 给楼层居民打电话 如果他要给某户人打电话它会吧之前的每户都打一遍 问他在打给某房间号 按了多少个数字 其中 房间号 定义类似如下 第一层【1,11,111,1111】 第二层 【2,22,222,2222】 问题分析: 每层全拍 就是10个数字=1+2+3+4 最后一层 没户按键数量就是他目前的长度 看码,看码。 AC代码: #include<iostream> #

MaxVen 193

Codeforces Round #677 (Div. 3) 题解

Codeforces Round #677 (Div. 3) 题解 A. Boring Apartments 题目 题解 简单签到题,直接数,小于这个数的+10+10+10。 代码 #include <bits/stdc++.h> using namespace std; #define ll long long #define IOS ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0); const int maxn = 2e5 + 10

qq_40872103的博客 286
上一篇: 计蒜客 身高接近
下一篇: 校赛 凑硬币
Olga_jing
博客等级 码龄11年 4粉丝 35原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值