【链接】 我是链接,点我呀:)

【题意】

在这里输入题意

【题解】

二分最后的最大值的最小值。
得到ans
然后从后往前尽量划分。
如果发现不够分成k个。
那么就从第一个开始接着分restk个(每隔1个分1块
中间遇到之前分了的就直接跳过

【代码】

/*
1.Shoud it use long long ?
2.Have you ever test several sample(at least therr) yourself?
3.Can you promise that the solution is right? At least,the main ideal
4.use the puts("") or putchar() or printf and such things?
5.init the used array or any value?
6.use error MAX_VALUE?
7.use scanf instead of cin/cout?
8.whatch out the detail input require
*/
/*
一定在这里写完思路再敲代码!!!
二分最后的最大值的最小值。
得到ans
然后从后往前尽量划分。
如果发现不够分成k个。
那么就从第一个开始接着分restk个(每隔1个分1块
中间遇到之前分了的就直接跳过
*/
#include <bits/stdc++.h>
#define ll long long
using namespace std; const int N = 500; int n,k,a[N+10];
bool tag[N+10]; bool ok(ll up){
ll now = 0;
int times = 1;
for (int i = 1;i <= n;i++)
if (a[i]>up) return false;
else
{
now+=a[i];
if (now > up){
now = a[i];
times++;
}
}
return times<=k;
} int main(){
#ifdef LOCAL_DEFINE
freopen("rush_in.txt", "r", stdin);
#endif
ios::sync_with_stdio(0),cin.tie(0);
int T;
cin >> T;
while (T--){
memset(tag,0,sizeof tag);
cin >> n >> k;
for (int i = 1;i <= n;i++) cin >> a[i];
ll l = 0,r = 50e8,temp = -1;
while (l <= r){
ll mid = (l+r)>>1;
if (ok(mid)){
temp = mid;
r = mid-1;
}else l = mid + 1;
}
k--;
ll now = a[n];
for (int i = n-1;k>0 && i >= 1;i--){
now += a[i];
if (now > temp){
k--;
now = a[i];
tag[i] = 1;
}
}
if (k > 0){
for (int i = 1;k>0 && i <= n;i++)
if (!tag[i]){
tag[i] = 1;
k--;
}
}
for (int i = 1;i <= n;i++)
{
cout << a[i];
if (tag[i]) cout <<" /";
if (i!=n) cout << ' ';else cout << endl;
}
}
return 0;
}

【例题 8-10 UVA - 714】 Copying Books的更多相关文章

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

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

  2. UVa 714 Copying Books(二分)

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

  3. UVA 714 Copying Books 二分

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

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

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

  5. 【NOIP提高组2015D2T1】uva 714 copying books【二分答案】——yhx

    Before the invention of book-printing, it was very hard to make a copy of a book. All the contents h ...

  6. UVa 714 Copying Books - 二分答案

    求使最大值最小,可以想到二分答案. 然后再根据题目意思乱搞一下,按要求输出斜杠(这道题觉得就这一个地方难). Code /** * UVa * Problem#12627 * Accepted * T ...

  7. UVA - 714 Copying Books (抄书)(二分+贪心)

    题意:把一个包含m个正整数的序列划分成k个(1<=k<=m<=500)非空的连续子序列,使得每个正整数恰好属于一个序列(所有的序列不重叠,且每个正整数都要有所属序列).设第i个序列的 ...

  8. uva 714 - Copying Books(贪心 最大值最小化 二分)

    题目描写叙述开头一大堆屁话,我还细致看了半天..事实上就最后2句管用.意思就是给出n本书然后要分成k份,每份总页数的最大值要最小.问你分配方案,假设最小值同样情况下有多种分配方案,输出前面份数小的,就 ...

  9. UVA 714 Copying Books

    题意: 要抄N本书,编号为1,2,3...N, 每本书有1<=x<=10000000页, 把这些书分配给K个抄写员,要求分配给某个抄写员的那些书的编号必须是连续的.每个抄写员的速度是相同的 ...

  10. UVa 714 Copying books 贪心+二分 最大值最小化

    题目大意: 要抄N本书,编号为1,2,3...N, 每本书有1<=x<=10000000页, 把这些书分配给K个抄写员,要求分配给某个抄写员的那些书的编号必须是连续的.每个抄写员的速度是相 ...

随机推荐

  1. 惊叹计算机运行速度的提升---以n Queens 问题为例

    1 介绍 实现了书<Data Structures and Program design in C++>(Robert L. Kruse and Alexander J. Ryba, 20 ...

  2. url与图片

    http://restapi.amap.com/v3/staticmap?location=116.481485,39.990464&zoom=10&size=750*300& ...

  3. HDU 5883 欧拉回路

    题面: 思路: 这里面有坑啊啊啊-.. 先普及一下姿势: 判断无向图欧拉路的方法: 图连通,只有两个顶点是奇数度,其余都是偶数度的. 判断无向图欧拉回路的方法: 图连通,所有顶点都是偶数度. 重点:图 ...

  4. Android 使用TabLayout、ViewPager和Fragment实现顶部菜单可滑动切换

    效果图如下 首先,要使用控件需要添加design library,在Android Studio中添加 compile 'com.android.support:design:23.4.0' 然后是布 ...

  5. Android中Service的一个Demo例子

    Android中Service的一个Demo例子  Service组件是Android系统重要的一部分,网上看了代码,很简单,但要想熟练使用还是需要Coding.  本文,主要贴代码,不对Servic ...

  6. valgrind的说明使用和原理

    编译 #gcc -g -o test test.c 内存检查#valgrind --tool=memcheck --leak-check=yes --show-reachable=yes ./test ...

  7. iOS 平台上常见的安装包有三种,deb、ipa 和 pxl

    前言:目前 iOS 平台上常见的安装包有三种,deb.ipa 和 pxl. 其中 deb 格式是 Debian 系统(包含 Debian 和 Ubuntu )专属安装包格式,配合 APT 软件管理系统 ...

  8. BZOJ 2708 [Violet 1]木偶 DP

    题意:id=2708">链接 方法: DP 解析: 这题太神辣. 做梦都没想到DP啊,反正我不会. 先谈一个我有过的错的想法. 最小费用最大流? 能匹配的边连费用为1的,不能匹配的连费 ...

  9. 认识 Atlassian Datacenter 产品

    认识 Atlassian Datacenter 产品 云端原本就是群集化的架构,Atlassian 系列产品.应用的开发团队相当广范且行之有年,可是将应用程序作为节点(比方Jira,confluenc ...

  10. JSP从选择到放弃

    JSP为什么会出现?出现的原因? ①因为在开发web网站时候,返现servlet做界面比较麻烦,于是出现了jsp. 运行在服务端(Java server pages)基于servlet,对servle ...