POJ 1505 (Copying Books)(经典二分)

三相电路小白必看:正弦量向量表示法保姆级教程(附欧拉公式推导) 本文为电气工程初学者详细解析了三相电路中正弦量的向量表示法,即相量法。通过几何直观和欧拉公式推导,阐明如何将时变正弦量转化为静态复平面向量进行运算,并利用平行四边形法则简化同频正弦量的加减计算。文章结合Python代码进行可视化验证,帮助读者牢固掌握这一分析交流电路的核心工具。 阅读详情

Description

Before the invention of book-printing, it was very hard to make a copy of a book. All the contents had to be re-written by hand by so called scribers. The scriber had been given a book and after several months he finished its copy. One of the most famous scribers lived in the 15th century and his name was Xaverius Endricus Remius Ontius Xendrianus (Xerox). Anyway, the work was very annoying and boring. And the only way to speed it up was to hire more scribers. 

Once upon a time, there was a theater ensemble that wanted to play famous Antique Tragedies. The scripts of these plays were divided into many books and actors needed more copies of them, of course. So they hired many scribers to make copies of these books. Imagine you have m books (numbered 1, 2 ... m) that may have different number of pages (p1, p2 ... pm) and you want to make one copy of each of them. Your task is to divide these books among k scribes, k <= m. Each book can be assigned to a single scriber only, and every scriber must get a continuous sequence of books. That means, there exists an increasing succession of numbers 0 = b0 < b1 < b2, ... < b k-1 <= bk = m such that i-th scriber gets a sequence of books with numbers between bi-1+1 and bi. The time needed to make a copy of all the books is determined by the scriber who was assigned the most work. Therefore, our goal is to minimize the maximum number of pages assigned to a single scriber. Your task is to find the optimal assignment. 

Input

The input consists of N cases. The first line of the input contains only positive integer N. Then follow the cases. Each case consists of exactly two lines. At the first line, there are two integers m and k, 1 <= k <= m <= 500. At the second line, there are integers p1, p2, ... pm separated by spaces. All these values are positive and less than 10000000.

Output

For each case, print exactly one line. The line must contain the input succession p1, p2, ... pm divided into exactly k parts such that the maximum sum of a single part should be as small as possible. Use the slash character ('/') to separate the parts. There must be exactly one space character between any two successive numbers and between the number and the slash. 

If there is more than one solution, print the one that minimizes the work assigned to the first scriber, then to the second scriber etc. But each scriber must be assigned at least one book.

Sample Input

2
9 3
100 200 300 400 500 600 700 800 900
5 4
100 100 100 100 100

Sample Output

100 200 300 400 500 / 600 700 / 800 900
100 / 100 / 100 / 100 100

Source



题意:给你n本书,k个人翻译,问怎样分配一个人单独翻译的最大值最小,换而言之,每个人翻译的差不多,

还有一个要求,就是如果可以,尽量让第一个人翻译的少



思路:先二分找出一个人翻译的最大值,然后找出每个人的翻译的(从后到前找),有一个bug,让我cuo了11发,%>_<%

我在代码中说明


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdio>
using namespace std;

#define N 505

int a[N],vis[N];

int n,k;

int seach(int mid)  //每个人翻译mid本书,看看需要的人数能不能少于等于k
{
    int step=1,cur=0,i;

    for(i=1;i<=n;i++)
     if(cur+a[i]<=mid)
        cur+=a[i];
     else
     {
         step++;
         cur=a[i];
     }

     if(step<=k) return 1;
     return 0;
}

int main()
{
    int i,t,le,ri;

    scanf("%d",&t);


    while(t--)
    {

        scanf("%d%d",&n,&k);

        le=ri=0;

        for(i=1;i<=n;i++)
            {
                scanf("%d",&a[i]);
                if(a[i]>le) le=a[i];
                ri+=a[i];
            }

        int ans,mid;

        while(le<=ri)
        {
            mid=(le+ri)/2;
            if(seach(mid))
            {
                ans=mid;
                ri=mid-1;
            }
            else
                le=mid+1;
        }

       memset(vis,0,sizeof(vis));

       int x=k,j,temp=0;

       for(i=n;i>=1;i--)
       {
            if(x>i)  //这是bug关键,如果人数比数的本书多,后面的人一人一本
           {         //这里情况很复杂 请认真结合我下面给的样例想想,=和>的区别
                     //我比赛时错了 11发(就是这没考虑)
            for(i;i>=1;i--)
                 vis[i]=1;
                break;
           }

           temp+=a[i];
           if(temp>ans)
           {
               temp=a[i];
               vis[i]=1;
               x--;    //人数减一
           }


       }

       for(i=1;i<=n;i++)
        {
            if(i==1)
               printf("%d",a[i]);
            else
               printf(" %d",a[i]);

            if(vis[i]) printf(" /");
        }
      printf("\n");
   }
   return 0;
}



// n=4  k=4
//当ans=200

// 20 100 100 200

//如果我上面强调的(x>i),那么100 和 100之间不会有 /
//还有为什么是 > 不是 >= 呢,再给一组数据

//  n=6,k=5,ans=200

// 50 100 50 50 50 200

//结果  50/100/50/50/50/200,就会出错,请认真思考(毕竟我当时快崩溃了)


我错了11次,当时ac简直无法形容我的感觉,如有解释不当的地方,欢迎指出

上面二分简单就没有解释多少,请注意我强调的地方

(八)DDR_PHY架构及功能——(PUB组成、初始化及Training流程、Clock关系) 文章目录一、DDR_PHY结构组成1.1、DDR Memory子系统1.2、DDR_PHY架构组成1.3、PUB模块功能实现流程1.3.1、DDR系统初始化流程1.3.2、PLL初始化流程 一、DDR_PHY结构组成 1.1、DDR Memory子系统   Memory子系统主要由DDR Controller和DDR_PHY(含DDR_IO)两个部分组成。DDR Controller主要承担其它子系统(如CPU)与Memory子系统进行数据交互时的传输效率及调度,DDR_PHY主要负责数据交互过程中的传输速 阅读详情

相关推荐

基于Python爬虫的新闻热点分析与挖掘

本文介绍了基于Python爬虫的新闻热点分析与挖掘方法,主要包括数据收集、预处理、热点分析和可视化四个部分。首先通过爬虫抓取新浪新闻数据,利用文本清洗和存储技术进行数据预处理;接着采用TF-IDF和LDA算法进行关键词提取与主题建模;最后通过词云图和主题分布图实现数据可视化。该方法能有效识别新闻热点,为信息筛选和决策提供支持。

专注于Python爬虫开发,分享爬虫技巧、项目实战与反爬经验,使用Scrapy、BeautifulSoup等工具,解决数据抓取难题。 1544

poj(1505)——Copying Books

这是一道关于求最大值最小化的问题。 虽然卡了不少时间,但是最后还是完全凭借自己的力量A的呢!yep~ 题意: 现在有m本书,然后每本书有不同的页数,然后现在有k名员工,你可以把m本书划分给k名员工,也就是相当于把m划分成k个序列,你的任务是使所有的k个序列中的最大值尽量小。并输出划分情况。 当有多种划分情况时,必须保证第一个人所工作量最少,然后依次第二个。。。 思路: 最大值最小化的问

ACM_hades的梦想之路 936

别再瞎调了!STM32 Systick延时函数避坑指南(正点原子、野火、慧净代码对比)

本文深入解析STM32 Systick延时函数的实现差异与优化策略,对比正点原子、野火、慧净等主流方案的优缺点。针对us和ms级延时精度问题,提供避坑指南和高级优化技巧,帮助开发者根据项目需求选择最佳方案,提升嵌入式系统的定时控制精度。

weixin_28717807的博客 340

POJ 1505(二分+贪心)

题意:给一些书,这些书有不同的页数,让把这些书分成k份,必须是连续的,问这些份中页数和的最大值最小是多少。 解题思路:知道了页数和的范围,而且书都是连续的,要找到页数和最大值的最小值可以直接二分答案。。 AC: #include #include #include using namespace std; const int MAXM = 505; int m,k; int book[MA

hexianhao的博客 720

OpenSees入门指南:从零开始的环境配置与TCL脚本实战

本文提供了一份详细的OpenSees入门指南,涵盖从零开始的环境配置到TCL脚本实战的全过程。文章重点讲解了OpenSees的安装步骤、环境变量设置,并推荐了高效的VS Code集成开发环境配置方法。通过一个简支梁分析的完整TCL脚本示例,手把手引导读者完成第一个非线性有限元分析,帮助土木工程与结构工程领域的研究者与学生快速上手这一强大的开源分析工具。

weixin_28829339的博客 336

Simplicity Studio V5与EFR32BG22蓝牙开发环境实战指南

本文详细介绍了Simplicity Studio V5集成开发环境与EFR32BG22蓝牙芯片的开发实战指南。内容涵盖开发环境安装、SDK配置、项目创建、调试烧录、外设驱动集成及常见问题解决方案,帮助开发者快速上手物联网蓝牙应用开发,并充分利用EFR32BG22的低功耗与高集成度特性。

v5w6x的博客 320

POJ 1505:二分枚举+贪心

POJ 1505:二分枚举+贪心 二分枚举解空间+贪心判断解可行性的方法,适合很多形如求解Min{Max{…}}、Max{Min{…}}且具有单调性的问题。像:POJ 1505 Copying Books 求:分配方案,使最后完成的时间最短。POJ 1771 Elevator Stopping Plan 求:电梯停靠策略,使最后一个到达办公室的时间最短。…还有今年ICPC world final的

陈满的专栏 1559

计算机组成原理课程设计_微程序控制的简单模型机设计

微程序控制的简单模型机设计 要求 基本要求 完成一个简单主机的设计,模型机应具备如下能力:在自行设计的指令集基础上,运行自行编写的简单用户程序,实现特定运算功能。 弹性要求 在此基础上,完成必要的扩展,实现模型机的功能扩展设计,包括:实现多种运算功能(指令集的扩充)、支持更为丰富的寻址方式、有更为完善的微程序设计等。 实验软件和硬件环境 QuartusII, FPGA计算机组...

sailist的记录站 3万+

UVA 714 Copying Books

题意:按顺序给你N个数,将这N个数分成连续的M段,使得这M段每段的和中的最大值最小,输出最小值(1<=N<=100000,1<=M<=N,每个数在1到10000之间),如果有多种可能的话,尽量在前面进行划分。 思路: 1、由于函数具有单调性的特征,因此可以用二分枚举的办法去实现它,这与POJ3258有非常相似的地方,但这里不需要排序。 2、输出的时候需要用到贪心...

weixin_30830327的博客 138

c# U盘禁用---守护进程(插入,拔出,卸载等操作)

一、简介 传统的对U盘禁用,我们多采用修改注册表的方式,详情参考:https://blog.youkuaiyun.com/qq_25372599/article/details/79815407;本文将介绍一种其他的方式–后台守护程序。其原理非常简单:当守护程序检测到U盘的插入信号,我们自动卸载U盘,致使系统无法识别U盘,达到禁用U盘的效果。 二、程序设计 2.1 变量定义 strin...

星星之火燃亮码空 2845

常见js手撕题及算法总结

设计一个lazyMan,实现以下功能: LazyMan(‘Tony’); // Hi I am Tony LazyMan(‘Tony’).sleep(10).eat(‘lunch’); // Hi I am Tony // 等待了10秒… // I am eating lunch LazyMan(‘Tony’).eat(‘lunch’).sleep(10).eat(‘dinner’); // H...

没有名字适合我的博客 3176

【poj 1505】 Copying Books

题意:现在要把m本有顺序的书分给k个人复制(抄写),每一个人的抄写速度都一样,一本书不允许给两个(或以上)的人抄写,分给每一个人的书,必须是连续的,比如不能把第一、第三和第四本书给同一个人抄写。现在请你设计一种方案,使得复制时间最短。复制时间为抄写页数最多的人用去的时间。如果有多组解的话先要保证第一个人抄的尽量少,若仍有多组解,要先保证第二个人抄的尽量少,以此类推。要注意一下,保证前面的尽量小,前面

yhf_2015 572

C2000ware介绍

C2000的下载安装指南C2000目录。

小柚子的博客 2796

POJ 1505 Copying Books

Copying Books Time Limit: 3000MS Memory Limit: 10000K Total Submissions: 10819 Accepted: 3349 Description Before the invention of book-printing, it was very hard to make a copy of a book. All the co...

日拱一卒,功不唐捐 2818

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

poj1505Copying Books 二分+贪心详细总结

前两天花了时间理解了nyoj的586疯牛和nyoj619青蛙过河,满以为自己能重新写出这道题。。。谁知道。。。。。这里记录详细总结,希望下次看的时候能一目了然

The_b-dn 2979

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

Copying Books POJ - 1505 二分答案 详细注释

Copying Books POJ - 1505 Before the invention of book-printing, it was very hard to make a copy of a book. All the contents had to be re-written by hand by so called scribers. The scriber had been...

种花家的奋斗兔的博客 774

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

poj 1505 Copying Books 二分

二分的时候左边的初始值弄错了,一直wa. 5 3 1 1 1 1 10 1 / 1 1 1 / 10 View Code #include <stdio.h>int m,n,k,a,ar[505];void solve(int mid){ int i,j,s=0; for (i=0;i<n;i++) { if(ar[i]+...

diaopi1575的博客 153

POJ1505 Copying Books

ZOJ2002 题目 Before the invention of book-printing, it was very hard to make a copy of a book. All the contents had to be re-written by hand by so called scribers. The scriber had been given a book...

weixin_30505751的博客 172

[二分][细节]Copying Books POJ1505

Before the invention of book-printing, it was very hard to make a copy of a book. All the contents had to be re-written by hand by so called scribers. The scriber had been given a book and after several months he finished its copy. One of the most famous s

Cloth的博客 595

POJ1505 Copying Books(二分法)

B -二分 Time Limit:3000MSMemory Limit:0KB64bit IO Format:%lld & %llu Description Before the invention of book-printing, it was very hard to make a copy of a book. ...

Dara2015的博客 397

POJ1505:Copying Books 解题心得

原题: Description Before the invention of book-printing, it was very hard to make a copy of a book. All the contents had to be re-written by hand by so calledscribers. The scriber had been ...

advyne9986的博客 225

poj 1505 Copying Books

题目链接:http://poj.org/problem?id=1505 题目大意及思路:m个抄写员抄写n篇文章,使工作量最大的尽量小,且输出最小字典序。有两种方法可以做,dp和二分答案,二分答案较快。 dp: #include #include #include #include #include #include #include #include #include #include #i

Wings_of_Liberty的专栏 759

POJ 1505 Copying Books 二分 + 贪心

来源:http://poj.org/problem?id=1505 题意:给一些书,这些书有不同的页数,让把这些书分成k份,必须是连续的,问这些份中页数和的最大值最小是多少。 思路:首先可以用二分枚举出最大的最小值,然后输出的时候从后向前判断输出 代码: #include #include #include #include #include using namespace st

2214

POJ 1505 Copying Books(贪心 - 二分 + 最小化最大值)

链接:http://poj.org/problem?id=1505   题意:

Sun 398

poj1505 Copying Books

这题用的是dp, 他要求的是计算在这一排书中, 每个抄写员都要抄写这些书中得一部分连续的书。 这题的状态转移时:dist[i][j] = min(max(dist[i - 1][t], p[k](j>=k >=1+t)) ( i<= t < j); 其中i是第几个抄写员 ,j是抄写员从第t本书抄到第j本书。dist[i][j], 是前i个抄写员共抄J...

221
上一篇: HDU 1231 最大连续子序列
下一篇: ZOJ 1586(最小生成树)
左眼皮跳跳~
博客等级 码龄13年 17粉丝 400原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值