当前位置:网站首页>Haut OJ 1316: sister choice buys candy III
Haut OJ 1316: sister choice buys candy III
2022-07-05 05:16:00 【hunziHang】
Problem description :
Choice The schoolgirl looks at so many sweets in the candy store , She thought it would be great if she could take them all home . Now there are n Grow candy (1-n Number ), Each kind of candy has mi individual (mi On behalf of the i The number of candies ),Choice The student sister only has two paper bags , Each paper bag can hold at most w A candy .Choice The schoolgirl doesn't want a paper bag mixed with a variety of sweets ( One paper bag at a time can only contain one kind of candy ), that Choice How many times does the schoolgirl have to take all these sweets home at least ?
Input :
Enter two integers on the first line n,w(1 <= n ,w<= 1e4), Space off
Next line n Space separated integers mi, It means the first one i The number of candies .(1<= mi <= 1e3).
Output :
How many times should I take the output at least , The answer is on one line .
The sample input :
6 5 3 2 6 5 4 4
Sample output :
4
Cause analysis :
Calculate the total number of bags needed , Number of bags /2 According to the circumstances , Because because / The result is an integer , That is, odd numbers will be rounded down , One less time , So you can Odd number Even numbers Merge (ans+ 1) / 2 for example 7/2=3 , Mathematically, it should be equal to 3.5, The actual need 4 Time , even numbers 8 need 4 Time , Add 1 There are still four times Actually ans/2 + 0.5 +0.5 It is equivalent to rounding
in the future Practical application /2 Remember to think about Odd and even cases , Whether it will have an impact
Solution :
#include <stdio.h>
int main()
{
int n, w, t;
int ans = 0;
scanf("%d%d", &n, &w);
for(int i = 1; i <= n; i++) {
scanf("%d", &t);
ans += t / w;
if(t % w)
ans ++;
}
printf("%d\n", (ans+ 1) / 2);
return 0;
}
边栏推荐
- Panel panel of UI
- django连接数据库报错,这是什么原因
- Ue4/ue5 illusory engine, material part (III), material optimization at different distances
- To the distance we have been looking for -- film review of "flying house journey"
- [turn to] MySQL operation practice (I): Keywords & functions
- Download and use of font icons
- win10虚拟机集群优化方案
- Use of snippets in vscode (code template)
- [LeetCode] 整数反转【7】
- Solon 框架如何方便获取每个请求的响应时间?
猜你喜欢

Ue4/ue5 illusory engine, material part (III), material optimization at different distances

django连接数据库报错,这是什么原因

UE 虚幻引擎,项目结构

质量体系建设之路的分分合合
![[turn to] MySQL operation practice (I): Keywords & functions](/img/b1/8b843014f365b786e310718f669043.png)
[turn to] MySQL operation practice (I): Keywords & functions

Double pointer Foundation
![[to be continued] [UE4 notes] L1 create and configure items](/img/20/54ba719be2e51b7db5b7645b361e26.jpg)
[to be continued] [UE4 notes] L1 create and configure items

Chinese notes of unit particle system particle effect

用 Jmeter 工具做个小型压力测试

Establish cloth effect in 10 seconds
随机推荐
Research on the value of background repeat of background tiling
Unity writes timetables (without UI)
A complete attack chain
[allocation problem] 455 Distribute cookies
C language Essay 1
《动手学深度学习》学习笔记
Cocos2dx screen adaptation
[轉]: OSGI規範 深入淺出
LeetCode之單詞搜索(回溯法求解)
2022年上半年国家教师资格证考试
Simple HelloWorld color change
Generate filled text and pictures
一个新的微型ORM开源框架
Dotween usage records ----- appendinterval, appendcallback
嵌入式数据库开发编程(五)——DQL
Download xftp7 and xshell7 (official website)
十年不用一次的JVM调用
Solon 框架如何方便获取每个请求的响应时间?
Romance of programmers on Valentine's Day
To the distance we have been looking for -- film review of "flying house journey"