首先通过二分来确定这种最大值最小的问题。

假设每个区间的和的最大值为x,那么只要判断的时候只要贪心即可。

也就是如果和不超过x就一直往区间里放数,否则就开辟一个新的区间,这样来判断是否k个区间容得下这些数。

还有就是输出也挺麻烦的,借鉴了一下lrj的代码,感觉也是十分巧妙。

 #include <bits/stdc++.h>
using namespace std; typedef long long LL;
const int maxn = + ;
LL a[maxn];
bool last[maxn];
int n, k; bool check(LL x)
{
int cnt = ;
for(int i = , j; i < n; i = j)
{
if(cnt > k) return false;
LL s = ;
for(j = i; j < n; j++)
{
if(a[j] > x) return false;
if(s + a[j] <= x) s += a[j];
else break;
}
cnt++;
}
return true;
} int main()
{
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout); int T; scanf("%d", &T);
while(T--)
{
scanf("%d%d", &n, &k);
LL L = , R = ;
for(int i = ; i < n; i++) { scanf("%lld", &a[i]); R += a[i]; }
while(L < R)
{
LL mid = (L + R) / ;
if(check(mid)) R = mid;
else L = mid + ;
} memset(last, false, sizeof(last));
LL s = ; int r = k;
for(int i = n-; i >= ; i--)
{
if(s + a[i] > L || i + < r)
{
last[i] = true;
s = a[i];
r--;
}
else s += a[i];
}
for(int i = ; i < n-; i++)
{
printf("%lld ", a[i]);
if(last[i]) printf("/ ");
}
printf("%lld\n", a[n-]);
} return ;
}

代码君

UVa 714 (二分) Copying Books的更多相关文章

  1. 【uva 714】Copying Books(算法效率--二分+贪心)

    题意:将1个含N个正整数的序列划分成K个连续的子序列,使每段的和的最大值尽量小,问字典序最小的划分方案. 解法:由于是连续的数的"最大值最小",便可想到二分每段的最大值,若这时可分 ...

  2. 【例题 8-10 UVA - 714】 Copying Books

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 二分最后的最大值的最小值. 得到ans 然后从后往前尽量划分. 如果发现不够分成k个. 那么就从第一个开始接着分restk个(每隔1 ...

  3. UVa 714 Copying Books(二分)

    题目链接: 传送门 Copying Books Time Limit: 3000MS     Memory Limit: 32768 KB Description Before the inventi ...

  4. UVA 714 Copying Books 二分

    题目链接: 题目 Copying Books Time limit: 3.000 seconds 问题描述 Before the invention of book-printing, it was ...

  5. UVA 714 Copying Books 最大值最小化问题 (贪心 + 二分)

      Copying Books  Before the invention of book-printing, it was very hard to make a copy of a book. A ...

  6. uva 714 Copying Books(二分法求最大值最小化)

    题目连接:714 - Copying Books 题目大意:将一个个数为n的序列分割成m份,要求这m份中的每份中值(该份中的元素和)最大值最小, 输出切割方式,有多种情况输出使得越前面越小的情况. 解 ...

  7. 抄书 Copying Books UVa 714

    Copying  Books 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=85904#problem/B 题目: Descri ...

  8. Copying Books

    Copying Books 给出一个长度为m的序列\(\{a_i\}\),将其划分成k个区间,求区间和的最大值的最小值对应的方案,多种方案,则按从左到右的区间长度尽可能小(也就是从左到右区间长度构成的 ...

  9. poj 1505 Copying Books

    http://poj.org/problem?id=1505 Copying Books Time Limit: 3000MS   Memory Limit: 10000K Total Submiss ...

随机推荐

  1. 10 个让人惊讶的 jQuery 插件

    说是让人惊讶,你可能会觉得我们没见过世面,但这里提及的一些 jQuery 的插件的确平时比较少见,用的人应该更少. Grid portfolio 使用竖排方式显示条目信息,现在很流行的的内容布局方式. ...

  2. Unity3D 运营商支付 安卓打包的陷阱 libunicomsdk.jar

    原地址:http://blog.csdn.net/alking_sun/article/details/36624491 想想做Unity3D SDK集成已经快2年了,遇到过不少很棘手的SDK,其中以 ...

  3. HDU 2672 god is a girl (字符串处理,找规律,简单)

    题目 //1,1,2,3,5,8,13,21,34,55…… //斐波纳契数列 #include<math.h> #include<stdio.h> #include<s ...

  4. UVA 11795

    B Mega Man’s Missions Input Standard Input Output Standard Output Mega Man is off to save the world ...

  5. POJ 2001

    #include<iostream> using namespace std; ; struct trienode { trienode * next[kind]; int branch; ...

  6. POJ 1401

    #include<iostream>using namespace std;int main(){    int num;    int i;    int sum;    cin> ...

  7. 项目中用到的SQL-总结

    基本sql总结: Group by的理解:having子句,分组函数 Group by使用的限定: 1.出现在Select列表中的字段或者出现在order by后面的字段,如果不是包含在分组函数中,那 ...

  8. Xamarin for Visual Studio 3.11.666 Beta版 破解补丁

    注意:本版本是 Beta 版   现已推送到稳定频道 前提概要 全新安装请参考 安装 Xamarin for Visual Studio. 最新稳定版请参考 Xamarin for Visual St ...

  9. Integral类型的跨平台使用

    fundamental integral types or extended integral types 我们先通过下图,来了解可以跨平台使用的整数类型: 之所以我们需要以上各种明确指定宽度的int ...

  10. dom对象详解--document对象(三)

     form对象 form对象代表一个HTML表单,在HTML文档中<form>每出现一次,form对象就会被创建.从dom对象层次图看,document.forms对象是当前文档所有for ...