当前位置:网站首页>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;
}
边栏推荐
- Solon 框架如何方便获取每个请求的响应时间?
- 对象的序列化
- Redis has four methods for checking big keys, which are necessary for optimization
- Chinese notes of unit particle system particle effect
- Leetcode word search (backtracking method)
- cocos2dx_ Lua card flip
- Recherche de mots pour leetcode (solution rétrospective)
- Dotween usage records ----- appendinterval, appendcallback
- Personal required code
- Lua wechat avatar URL
猜你喜欢
Django reports an error when connecting to the database. What is the reason
【论文笔记】Multi-Goal Reinforcement Learning: Challenging Robotics Environments and Request for Research
Reverse one-way linked list of interview questions
[转]: OSGI规范 深入浅出
对象的序列化
嵌入式数据库开发编程(五)——DQL
Redis has four methods for checking big keys, which are necessary for optimization
Applet Live + e - commerce, si vous voulez être un nouveau e - commerce de détail, utilisez - le!
[trans]: spécification osgi
支持多模多态 GBase 8c数据库持续创新重磅升级
随机推荐
National teacher qualification examination in the first half of 2022
C language Essay 1
Unity ugui source code graphic
Reverse one-way linked list of interview questions
[转]MySQL操作实战(三):表联结
Unity shot tracking object
Cocos progress bar progresstimer
C语言杂谈1
cocos2dx_ Lua particle system
Solon 框架如何方便获取每个请求的响应时间?
FVP和Juno平台的Memory Layout介绍
PR first time
小程序直播+電商,想做新零售電商就用它吧!
发现一个很好的 Solon 框架试手的教学视频(Solon,轻量级应用开发框架)
[turn to] MySQL operation practice (I): Keywords & functions
对象的序列化
Optimization scheme of win10 virtual machine cluster
Merge sort
TF-A中的工具介绍
Ue4/ue5 illusory engine, material part (III), material optimization at different distances