博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
codeforces 789A(数学)
阅读量:1905 次
发布时间:2019-04-26

本文共 2862 字,大约阅读时间需要 9 分钟。

A. Anastasia and pebbles
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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 most k pebbles in each pocket at the same time. There are n different pebble types in the park, and there are wi pebbles of the i-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.

Input

The first line contains two integers n and k (1 ≤ n ≤ 1051 ≤ 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.

Output

The only line of output contains one integer — the minimum number of days Anastasia needs to collect all the pebbles.

Examples
input
3 22 3 4
output
3
input
5 43 1 8 9 7
output
5
Note

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 and 1 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.
  • 题意:有n堆种类各不相同的东西需要移动位置,现在一件衣服上面有两个口袋,每个口袋最多放k件东西,并且要求一个口袋里面的东西必须是种类相同的。问最少需要的移动次数是多少?
  • 思路:分为几种情况,数量小于等于k的,数量在大于k并且小于2*k之间的,和数量大于等于2*k的,为什么这样分,先说小于k的,是不是只需要一个口袋,然后大于k并且小于2*k是不是需要两个口袋,数量大于等于2*k的,就要看是不是能被2*k整除了,如果不能那么又会产生第一和第二种情况。
  • 代码:
  • #include<bits/stdc++.h>
    using namespace std;
    const int maxn=1e5+5;
    typedef long long LL;
    int w[maxn];
    int main()
    {
        int n,k;
        while(scanf("%d%d",&n,&k)!=EOF)
        {
            for(int i=0;i<n;i++)
            {
                scanf("%d",&w[i]);
            }
            int num1=0,num2=0;
            int ans=0;
            int count1=0,count2=0;
            for(int i=0;i<n;i++)
            {
                int t=k*2;
               if(w[i]<=k)
               {
                   num1++;
                   continue;
               }
               if(w[i]>=t)
                {
                    count1=w[i]/t;
                    count2=w[i]%t;
                    ans+=count1;
                    if(count2<=k&&count2!=0) num1++;
                    if(count2>k&&count2<t) ans++;
                }
                if(w[i]>k&&w[i]<t)
                {
                    ans++;
                    continue;
                }
            }
           num2=(int)num1/2.0+0.5;
           ans+=num2;
           printf("%d\n",ans);
        }
        return 0;
    }

转载地址:http://jjncf.baihongyu.com/

你可能感兴趣的文章
四线触摸屏原理
查看>>
小议Linux staging tree
查看>>
C/C++如何返回一个数组/指针
查看>>
腾讯AI语音识别API踩坑记录
查看>>
YbtOJ——递推算法【例题4】传球游戏
查看>>
YbtOJ——字符串处理【例题1】数字反转
查看>>
转trt步骤记录
查看>>
MatConvNet安装
查看>>
依赖错误
查看>>
ROS安装与卸载
查看>>
openrave安装
查看>>
安装openrave 0.9的各种依赖包
查看>>
trajopt代码使用
查看>>
kpm代码使用细节
查看>>
可选的配置属性(Hibernate reference 3.2.0 ga 正式版中文参考手册)
查看>>
redis
查看>>
@FeignClient注解的重复名称解决
查看>>
ClassFile之Methods
查看>>
java.net.BindException: 无法指定被请求的地址
查看>>
scala list
查看>>