【例题 8-10 UVA - 714】 Copying Books
【链接】 我是链接,点我呀:)
【题意】
在这里输入题意
【题解】
二分最后的最大值的最小值。
得到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的更多相关文章
- uva 714 Copying Books(二分法求最大值最小化)
题目连接:714 - Copying Books 题目大意:将一个个数为n的序列分割成m份,要求这m份中的每份中值(该份中的元素和)最大值最小, 输出切割方式,有多种情况输出使得越前面越小的情况. 解 ...
- UVa 714 Copying Books(二分)
题目链接: 传送门 Copying Books Time Limit: 3000MS Memory Limit: 32768 KB Description Before the inventi ...
- UVA 714 Copying Books 二分
题目链接: 题目 Copying Books Time limit: 3.000 seconds 问题描述 Before the invention of book-printing, it was ...
- UVA 714 Copying Books 最大值最小化问题 (贪心 + 二分)
Copying Books Before the invention of book-printing, it was very hard to make a copy of a book. A ...
- 【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 ...
- UVa 714 Copying Books - 二分答案
求使最大值最小,可以想到二分答案. 然后再根据题目意思乱搞一下,按要求输出斜杠(这道题觉得就这一个地方难). Code /** * UVa * Problem#12627 * Accepted * T ...
- UVA - 714 Copying Books (抄书)(二分+贪心)
题意:把一个包含m个正整数的序列划分成k个(1<=k<=m<=500)非空的连续子序列,使得每个正整数恰好属于一个序列(所有的序列不重叠,且每个正整数都要有所属序列).设第i个序列的 ...
- uva 714 - Copying Books(贪心 最大值最小化 二分)
题目描写叙述开头一大堆屁话,我还细致看了半天..事实上就最后2句管用.意思就是给出n本书然后要分成k份,每份总页数的最大值要最小.问你分配方案,假设最小值同样情况下有多种分配方案,输出前面份数小的,就 ...
- UVA 714 Copying Books
题意: 要抄N本书,编号为1,2,3...N, 每本书有1<=x<=10000000页, 把这些书分配给K个抄写员,要求分配给某个抄写员的那些书的编号必须是连续的.每个抄写员的速度是相同的 ...
- UVa 714 Copying books 贪心+二分 最大值最小化
题目大意: 要抄N本书,编号为1,2,3...N, 每本书有1<=x<=10000000页, 把这些书分配给K个抄写员,要求分配给某个抄写员的那些书的编号必须是连续的.每个抄写员的速度是相 ...
随机推荐
- Qt中事件分发源码剖析
Qt中事件分发源码剖析 Qt中事件传递顺序: 在一个应该程序中,会进入一个事件循环,接受系统产生的事件,而且进行分发,这些都是在exec中进行的. 以下举例说明: 1)首先看看以下一段演示样例代码: ...
- 保存数据同一时候查询保存数据记录的ID
保存数据时同一时候取出该数据的记录ID insert into Table(a,b) values(1,2) select @@identity
- TRIZ系列-创新原理-7-嵌套原理
原理表述例如以下: 1)把一个物体嵌入另外一个物体.然后将这两个物体再嵌入第三个物体,以此类推. 这个原理又叫俄罗斯娃原理,目的是在不影响原有功能的情况下: A) 在须要时.能够降低系统的体积和便于携 ...
- sc命令以及InstallUtil安装service
1.安装 https://stackoverflow.com/questions/8164859/install-a-windows-service-using-a-windows-command-p ...
- AngularJS初接触
todo.json [ { "action": "Buy Flowers", "done": false }, { "action ...
- Integer 和 int的种种比较
public static void main(String[] args) { int i = 128; Integer i2 = 128; Integer i3 = new Integer(128 ...
- BZOJ 1578 DP
思路:裸的完全背包 //By SiriusRen #include <cstdio> #include <cstring> #include <algorithm> ...
- Design Pattern - Service Locator Pattern--转载
原文地址:http://www.tutorialspoint.com/design_pattern/service_locator_pattern.htm The service locator de ...
- window安装MQTT服务器和client
http://activemq.apache.org/apollo/download.html 官方下载地址 MQTT目录: MQTT简单介绍 window安装MQTT服务器和client ja ...
- node.学习笔记(关于http2的讲解)
个人总结:读完这篇文章需要30分钟 http2部分很有学习价值,可以好好看. 用node搭建TCP服务器 用node搭建HTTP服务器 用node文件fs模块对文件读取,并用流的方式写入 用url路 ...