• codevs3163 抄书问题2


    题目描述 Description

    现在要把M本有顺序的书分给K个人复制(抄写),每一个人的抄写速度都一样,一本书不允许给两个(或以上)的人抄写,分给每一个人的书,必须是连续的,比 如不能把第一、第三、第四本数给同一个人抄写。现在请你设计一种方案,使得复制时间最短。复制时间为抄写页数最多的人用去的时间。

    (本题数据范围扩大,本题支持 O(nk) 算法)

    输入描述 Input Description

    第一行两个整数M、K;(K<=1000 M<=10000  满足 k<=m)

    第二行M个整数,第i个整数表示第i本书的页数。

    输出描述 Output Description

    K行,每行两个正整数,第i行表示第i个人抄写的书的起始编号和终止编号。K行的起始编号应该从小到大排列,如果有多解,则尽可能让前面的人少抄写。

    样例输入 Sample Input

    9 3

    1 2 3 4 5 6 7 8 9

    样例输出 Sample Output

    1 5

    6 7

    8 9

    数据范围及提示 Data Size & Hint

    详见试题 

    本题支持 O(nk) 算法

    //注意最后的处理
    #include<iostream>
    #include<cstdio>
    #include<string>
    #include<cstring>
    #include<algorithm>
    using namespace std;
    const int maxn = 10005;
    int m,k,a[maxn],rec[maxn],tmp[maxn],s[maxn];
    bool check(int t){
        int p = k,w = 0;
        for(int i = m;i >= 1;i--){
        if(a[i] > t) return false;
    if(w + a[i] > t){ w = 0; p--; } if(!p) return false; w += a[i]; tmp[p] = i; } for(int i = 1;i <= k;i++) rec[i] = tmp[i]; return true; } int main(){ cin>>m>>k; for(int i = 1;i <= m;i++){ scanf("%d",&a[i]); s[i] = s[i-1] + a[i]; } int l = 1,r = s[m],mid; while(l <= r){ mid = (l + r) >> 1; if(check(mid)){ r = mid - 1; }else{ l = mid + 1; } } rec[k+1] = m + 1; if(rec[1] != 1) rec[1] = 1; for(int i = 2;i <= k;i++){ if(rec[i] <= rec[i-1]){ rec[i] = rec[i-1] + 1; continue; } break; } for(int i = 1;i <= k;i++){ cout<<rec[i]<<" "<<rec[i+1]-1<<endl; } return 0; }
  • 相关阅读:
    torch7框架 深度学习(1)
    ubuntu 14.04 安装torch及编译环境zbstudio
    win10 下使用虚拟机安装ubuntu及其网络配置
    Lua学习笔记4. coroutine协同程序和文件I/O、错误处理
    Lua学习笔记2. lua变量和 循环
    Lua学习笔记1,基本数据类型
    linux下如何安装lua
    结构性约束事件聚合下的在线多目标跟踪方法
    基于孪生卷积网络(Siamese CNN)和短时约束度量联合学习的tracklet association方法
    Git服务器 gitweb与gitLab的区别
  • 原文地址:https://www.cnblogs.com/hyfer/p/5791446.html
Copyright © 2020-2023  润新知