当前位置:网站首页>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;
}
边栏推荐
- [turn to] MySQL operation practice (III): table connection
- Solon Logging 插件的添加器级别控制和日志器的级别控制
- 2022上半年全国教师资格证下
- Optimization scheme of win10 virtual machine cluster
- Cocos progress bar progresstimer
- [paper notes] multi goal reinforcement learning: challenging robotics environments and request for research
- [merge array] 88 merge two ordered arrays
- Es module and commonjs learning notes
- Lua determines whether the current time is the time of the day
- Basic knowledge points
猜你喜欢

Django reports an error when connecting to the database. What is the reason

Stm32cubemx (8): RTC and RTC wake-up interrupt

Unity3d learning notes

LeetCode之單詞搜索(回溯法求解)
![[paper notes] multi goal reinforcement learning: challenging robotics environments and request for research](/img/17/db8614b177f33ee4f67b7d65a8430f.png)
[paper notes] multi goal reinforcement learning: challenging robotics environments and request for research

Simple modal box

Unity ugui source code graphic

Leetcode word search (backtracking method)
![[speed pointer] 142 circular linked list II](/img/f8/222a360c01d8ef120b61bdd2025044.jpg)
[speed pointer] 142 circular linked list II

Reverse one-way linked list of interview questions
随机推荐
xftp7与xshell7下载(官网)
win10虚拟机集群优化方案
十年不用一次的JVM调用
A complete attack chain
[turn]: OSGi specification in simple terms
UE4/UE5 虚幻引擎,材质篇(三),不同距离的材质优化
【ES实战】ES上的native realm安全方式使用
Learning notes of "hands on learning in depth"
2021-10-29
Vs2015 secret key
Unity3d learning notes
Bucket sort
Unity get component
Es module and commonjs learning notes
Solon Auth 认证框架使用演示(更简单的认证框架)
[allocation problem] 135 Distribute candy
Basic knowledge points
64 horses, 8 tracks, how many times does it take to find the fastest 4 horses at least
[turn]: Apache Felix framework configuration properties
Unity parallax infinite scrolling background