意甲冠军:k手稿的部分成m部分,使每一个和最小

思路:典型最大值最小化问题,使用贪心+二分。

贪心的是每次尽量将元素往右边划分,二分查找最小的x满足m个连续的子序列和S(i)都不超过x。

由于输出的原因。在划分时就从后往前尽量划分。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm> using namespace std; typedef long long ll;
const int MAXN = 1005; int m, k, t;
int arr[MAXN], vis[MAXN];
ll ans, sum, Min; int judge(ll x) {
memset(vis, 0, sizeof(vis));
ll s = 0;
t = 0;
int flag = 1;
for (int i = m - 1; i >= 0; i--) {
if (arr[i] > x) {
flag = 0;
break;
}
if (s + arr[i] > x) {
vis[i] = 1;
t++;
s = arr[i];
if (t > k - 1) {
flag = 0;
break;
}
}
else
s += arr[i];
}
return flag;
} int binary() {
ll x = Min, y = sum;
while (x < y) {
ll mid = x + (y - x) / 2;
if (judge(mid))
y = mid;
else
x = mid + 1;
}
return x;
} void outPut() {
judge(ans);
int num = k - 1 - t;
for (int i = 0; i < m; i++) {
if (vis[i] == 0 && num) {
vis[i] = 1;
num--;
}
}
for (int i = 0; i < m - 1; i++) {
printf("%d ", arr[i]);
if (vis[i])
printf("/ ");
}
printf("%d\n", arr[m - 1]);
} int main() {
int cas;
scanf("%d", &cas);
while (cas--) {
scanf("%d %d", &m, &k);
ans = 0;
Min = arr[0];
for (int i = 0; i < m; i++) {
scanf("%d", &arr[i]);
sum += arr[i];
if (Min < arr[i])
Min = arr[i];
} ans = binary();
outPut();
}
return 0;
}

版权声明:本文博客原创文章,博客,未经同意,不得转载。

UVA714- Copying Books(最大最小化)的更多相关文章

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

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

  2. POJ1505&amp;&amp;UVa714 Copying Books(DP)

    Copying Books Time Limit: 3000MS Memory Limit: 10000K Total Submissions: 7109 Accepted: 2221 Descrip ...

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

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

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

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

  5. 「个人训练」Copying Books(UVa714)

    好久不更新主要是怠惰了....还要加强训练. 题意分析与思路 注意到这样一句话: our goal is to minimize the maximum number of pages assigne ...

  6. UVa 714 Copying Books(二分)

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

  7. 抄书 Copying Books UVa 714

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

  8. UVA 714 Copying Books 二分

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

  9. poj 1505 Copying Books

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

随机推荐

  1. Why 使用TLS记录封装IP层VPN IS A Bad Idea

    一个很自然的想法,使用TLS套餐一IP数据报实现第三层VPN.这种想法必须经过深思熟虑的,但不幸的是,.这是一个错误的想法.有文章<Why TCP Over TCP Is A Bad Idea& ...

  2. Windows Phone开发(4):框架和页

    原文:Windows Phone开发(4):框架和页 在开如之前,我想更正一个小问题,之前我在第一篇文章中说,Visual Studio Express for Windows Phone的中文版没有 ...

  3. 什么是 CGI,什么是 IIS,什么是VPS

    该公司来到天.我们所从事的事情在网站上.这对我来说确实是一个很大的挑战.个人一直从事Android,对于web而一个开发网站server知识的几乎为零.在这里应该说,现在我只是有一个技术人员,昨天相遇 ...

  4. jquey :eq(1)

    $("#div_Goods .datagrid-row .numberbox:eq(1)") $("#div_Goods .datagrid-row .numberbox ...

  5. 关闭 sqlserver提示信息

  6. lua5.1 和 5.2 关于 sequence 的定义变化,对#table取值的影响

    引子 环境 lua 5.2 a = {}   for i=1,2 do a[i] = i*3 end   a[4] = 11;   print(a[#a])   ---print 11 ------- ...

  7. VMware装ubuntu 进不去图形界面, 卡在Installing VMware Tools

    1.按Ctrl +C结束,进入命令行 2.ubuntu login:_ 依次输入: 1)你的用户名:输入自己的! 2)你的密码:输入自己的! 3)获取root权限:sudo su 输密码 4)/etc ...

  8. B. Dreamoon and WiFi(Codeforces Round 272)

    B. Dreamoon and WiFi time limit per test 1 second memory limit per test 256 megabytes input standard ...

  9. effective c++ 条款18 make interface easy to use correctly and hard to use incorrectly

    举一个容易犯错的例子 class Date { private: int month; int day; int year; public: Date(int month,int day,int ye ...

  10. Unity3d该物业(Attributes)整理

    http://blog.sina.com.cn/s/blog_5b6cb9500101857b.html Attributes属性属于U3D的RunTimeClass,所以加上下面的命名空间是必须的了 ...