Choice學姐買糖果

題目鏈接:

                  有沒有AC 開動大腦

AC代碼:

#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;//記錄需要送幾次(需要幾個袋子)(取int)
//        printf("%d ",ans);
        if(t%w!=0)//如果是奇數再多送一次
            ++ans;
//        printf("%d\n",ans);
//        printf("---\n");
    }
//    printf("---\n");
    printf("%d\n",(ans+1)/2);//如果需要袋子數目是奇數再加一
    return 0;
}
最後在加一和小學題,安排學生上車是一樣的,吐過需要3.5輛車,則租用4輛車!(細思極恐小學題差點沒做出,gun回去上小學吧)


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章