zoukankan      html  css  js  c++  java
  • cf-789A (思维)

    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 ≤ 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.

    Output

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

    Examples
    input
    3 2
    2 3 4
    output
    3
    input
    5 4
    3 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.

     一开始写的超暴力970+ms水果。。后来看别人代码发现自己思维僵化!

    不一定非要一天一天的枚举,只要一个框子一个框子枚举最后根据框子推天数就很方便了!

    笨死啦!!!

    #include<bits/stdc++.h>
    using namespace std;
    inline int read()
    {
    	int x=0,f=1;char ch=getchar();
    	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    	return x*f;
    }
    int n,m,ans;
    int a;
    int main()
    {
    	n=read(),m=read();
    	for(int i=1;i<=n;i++)
    		a=read(),ans+=ceil(1.0*a/m);
    	printf("%d
    ",(int)(ceil(1.0*ans/2)));
    }
  • 相关阅读:
    python之__new__方法
    python之类也是一个对象
    python之面向对象中的多态
    python之多继承中的一些问题
    python之子类继承父类时进行初始化的一些问题
    Java深度历险(四)——Java垃圾回收机制与引用类型
    Java深度历险(三)——Java线程​:基本概念、可见性与同步
    Java深度历险(二)——Java类的加载、链接和初始化
    Java深度历险(一)——Java字节代码的操纵
    程序员面试什么最重要?
  • 原文地址:https://www.cnblogs.com/zzqc/p/6693142.html
Copyright © 2011-2022 走看看