• [ An Ac a Day ^_^ ] CodeForces 677B Vanya and Food Processor 模拟


    题意:

    你有一个榨汁机 还有n个土豆

    榨汁机可以容纳h高的土豆 每秒可以榨k高的东西

    问按顺序榨完土豆要多久

    思路:

    直接模拟

    一开始以为是最短时间排了个序 后来发现多余了……

     1 #include<stdio.h>
     2 #include<iostream>
     3 #include<algorithm>
     4 #include<math.h>
     5 #include<string.h>
     6 #include<string>
     7 #include<map>
     8 #include<set>
     9 #include<vector>
    10 #include<queue>
    11 #define M(a,b) memset(a,b,sizeof(a))
    12 using namespace std;
    13 typedef long long ll;
    14 int potato[100005];
    15 int main(){
    16     int n,h,k;
    17     scanf("%d%d%d",&n,&h,&k);
    18     for(int i=0;i<n;i++)
    19         scanf("%d",&potato[i]);
    20     ll ans=0,high=0;
    21     for(int i=0;i<n;i++){
    22         if(high+potato[i]<=h) high+=potato[i]; //能放下就放上去
    23         else{  //放不下就打完了再放
    24             high=potato[i]; 
    25             ans++;
    26         }
    27         ans+=high/k;
    28         high%=k;
    29     }
    30     if(high) ans++; //最后剩一点还要处理一下
    31     printf("%I64d
    ",ans);
    32     return 0;
    33 }
    34 /*
    35 
    36 5 6 3
    37 5 4 3 2 1
    38 
    39 5 6 3
    40 5 5 5 5 5
    41 
    42 5 6 3
    43 1 2 1 1 1
    44 
    45 */
  • 相关阅读:
    poj 1286
    poj 1815
    poj 3368
    十个利用矩阵乘法解决的经典题目
    poj 1026
    hdu 1394
    poj 3270
    poj 2154
    《重构 改善既有代码的设计》读书笔记2
    Android OpenGL ES: 渐变颜色的三角形
  • 原文地址:https://www.cnblogs.com/general10/p/5785597.html
Copyright © 2020-2023  润新知