zoukankan      html  css  js  c++  java
  • 小Biu的礼物——UPC

    题目描述

    小Biu送给小Piun个礼物,每个礼物的体积为v[i],现在小Piu有m个箱子,每个箱子的体积为k,去装这些物品,小Piu会从左到右依次选择每个物品,如果当前箱子可以放得下这个物品,就把物品放进去,否则就用下一个箱子,现在小Biu想知道他最少拿走前几个礼物,可以使得小Piu的箱子能装下剩下的所有物品。

    输入

    第一行三个整数n,m,k(1<=n,m,k<=100000).
    第二行n个整数,第i个整数为第i个礼物的体积v[i],(1<=v[i]<=100000)。
    输出
    输出一个数字表示小Biu最少从头拿走前几个物品,可以使得小Piu的箱子能装下剩下的所有物品。

    样例输入

    5 2 7
    1 2 3 4 5
    

    样例输出

    2
    

    提示

    样例解释:拿走前两个物品后,剩余物品体积为 3 4 5,按照规则可以依次用两个箱子装下物品。
    对于10%的数据,1<=n,m<=10
    对于25%的数据 1<=n,m<=1000
    对于100%的数据,1<=n,m<=100000

    本题的思想比较简单,从后往前进行模拟

    #pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
    #pragma GCC optimize("Ofast")
    #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
    #pragma comment(linker, "/stack:200000000")
    #pragma GCC optimize (2)
    #pragma G++ optimize (2)
    #include <bits/stdc++.h>
    #include <algorithm>
    #include <map>
    #include <queue>
    #include <set>
    #include <stack>
    #include <string>
    #include <vector>
    using namespace std;
    #define wuyt main
    typedef long long ll;
    #define HEAP(...) priority_queue<__VA_ARGS__ >
    #define heap(...) priority_queue<__VA_ARGS__,vector<__VA_ARGS__ >,greater<__VA_ARGS__ > >
    template<class T> inline T min(T &x,const T &y){return x>y?y:x;}
    template<class T> inline T max(T &x,const T &y){return x<y?y:x;}
    ///#define getchar()(p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++)
    ///char buf[(1 << 21) + 1], *p1 = buf, *p2 = buf;
    ll read(){ll c = getchar(),Nig = 1,x = 0;while(!isdigit(c) && c!='-')c = getchar();
    if(c == '-')Nig = -1,c = getchar();
    while(isdigit(c))x = ((x<<1) + (x<<3)) + (c^'0'),c = getchar();
    return Nig*x;}
    #define read read()
    const ll inf = 1e15;
    const int maxn = 2e5 + 7;
    const int mod = 1e9 + 7;
    #define start int wuyt()
    #define end return 0
    int cnt;
    string s;
    int num[maxn];
    ll temp=0;
    start{
        int n=read,m=read,k=read;
        for(int i=1;i<=n;i++) num[i]=read;
        for(int i=n;i>=1;i--){
            temp+=num[i];
            if(temp>k){
                cnt++;
                i++;
                temp=0;
            }
            if(cnt==m){
                printf("%d
    ",i-1);
                return 0;
            }
        }
        end;
    }
     
    /**************************************************************
        Language: C++
        Result: 正确
        Time:13 ms
        Memory:2804 kb
    ****************************************************************/
    
  • 相关阅读:
    POJ1239
    HDU 2829 四边形不等式优化
    返回数字二进制的最高位位数o(n)
    矩阵快速幂 模板
    HDU4718 The LCIS on the Tree(LCT)
    HDU4010 Query on The Trees(LCT)
    HDU3487 Play With Chains(Splay)
    CF444C DZY Loves Colors
    HDU4836 The Query on the Tree(树状数组&&LCA)
    HDU4831&&4832&&4834
  • 原文地址:https://www.cnblogs.com/PushyTao/p/13144175.html
Copyright © 2011-2022 走看看