CodeForces
来源:互联网 发布:python vps 编辑:程序博客网 时间:2024/06/03 19:16
Anastasia loves going for a walk in Central Uzhlyandian Park. But she became uninterested in simple walking, so she began to collect Uzhlyandian pebbles. At first, she decided to collect all the pebbles she could find in the park.
She has only two pockets. She can put at mostk pebbles in each pocket at the same time. There aren different pebble types in the park, and there arewi pebbles of thei-th type. Anastasia is very responsible, so she never mixes pebbles of different types in same pocket. However, she can put different kinds of pebbles in different pockets at the same time. Unfortunately, she can't spend all her time collecting pebbles, so she can collect pebbles from the park only once a day.
Help her to find the minimum number of days needed to collect all the pebbles of Uzhlyandian Central Park, taking into consideration that Anastasia can't place pebbles of different types in same pocket.
The first line contains two integers n andk (1 ≤ n ≤ 105,1 ≤ k ≤ 109) — the number of different pebble types and number of pebbles Anastasia can place in one pocket.
The second line contains n integers w1, w2, ..., wn (1 ≤ wi ≤ 104) — number of pebbles of each type.
The only line of output contains one integer — the minimum number of days Anastasia needs to collect all the pebbles.
3 22 3 4
3
5 43 1 8 9 7
5
In the first sample case, Anastasia can collect all pebbles of the first type on the first day, of second type — on the second day, and of third type — on the third day.
Optimal sequence of actions in the second sample case:
- In the first day Anastasia collects 8 pebbles of the third type.
- In the second day she collects 8 pebbles of the fourth type.
- In the third day she collects 3 pebbles of the first type and1 pebble of the fourth type.
- In the fourth day she collects 7 pebbles of the fifth type.
- In the fifth day she collects 1 pebble of the second type.
题意:一个人在公园见鹅卵石,他有两袋子,每个袋子最多装k个,但是一个带字一次不能装不同堆的石头,给你多堆石头,问你最少要用多少天能捡完
si
思路:如果一堆小于k那么计半天,如果一堆大于k小于2*k记1天,如果一堆大于2*k,那么把他分为若干堆 ,一部分的个数为2*k,剩下的一堆为n%2*k,规则还是和前边一样,最后技术
计数,整天数+半天数,如果半天数为偶数那么计为 半天数/2 ,否则计为 半天数/2+1
ac代码:
using namespacestd;
int main(){
int n,k,h; while(cin>>n>>k)
{
int p=0;
int q=0;
for(int i=1;i<=n;i++)
{
scanf("%d",&h);
if(h<=k)
p++;
if(h>k&&h<=2*k)
q++;
if(h>2*k)
{
q+=h/(2*k);
int d=h%(2*k);
if(d<=k&&d>0)
p++;
if(d>k)
q++;
}
}
if(p%2==0)
cout<<q+p/2<<endl;
else
cout<<q+p/2+1<<endl;
}
return 0;
}
- codeforces~~~
- Codeforces
- codeforces
- Codeforces
- codeforces
- codeforces
- Codeforces
- Codeforces
- CodeForces
- CodeForces
- CodeForces
- CodeForces
- CodeForces
- Codeforces
- Codeforces
- Codeforces
- Codeforces
- Codeforces
- bzoj1191: [HNOI2006]超级英雄Hero
- ubuntu下安装lxml
- DI v6.2,DI Governor在Linux下启动脚本startDIGovernor.sh编码格式问题导致启动失败
- 无法进入桌面you appear to be running an x server please exit x before installing
- 操作分区表对global和local索引的影响
- CodeForces
- 了解appium自动化的工作原理
- 异常代码
- 优化前端应用性能
- 移植madplay
- 解决国内NPM(node.js)安装依赖速度慢问题
- android 应用组件[通用 Intent---拍摄照片或视频并将其返回] 六
- 图像卷积与滤波的一些知识点(a)
- (freemarker)FTL常用标签及语法