ZOJ-2002 Copying Books

本文深入探讨了信息技术领域的核心内容,包括前端开发、后端开发、移动开发、游戏开发、大数据开发、开发工具等多个方面。从技术原理到实际应用,提供了全面的技术指导和案例分析,帮助读者掌握信息技术领域的最新趋势和实践方法。

Copying Books

Time Limit: 2 Seconds      Memory Limit: 65536 KB

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, ... < bk-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


通过二分和贪心,对数据进行划分,而且需要从后往前划分。



#include <stdio.h>
#include <stdlib.h>
long long getbase(long long*, int, int);
int partion(long long*, long long, int, int);

int main()
{
	int N, i, j, temp;
	int k, m, books[510], flag[510];
	int mid, l, r;
	long long b[510], midbase;
	scanf("%d", &N);
	while(N--) {
		scanf("%d%d", &m, &k);
		for(i = m; i > 0; i--) {
			scanf("%d", books + i);
		}
		b[0] = 0;
		for(i = 1; i <= m; i++) {
			b[i] = b[i-1] + books[i];
		}
		midbase = getbase(b, m, k);
		j = 0;
		temp = 0;
		for(i = 1; i <= k; i++) {
			while(1) {
				if(j > m || m-j < k-i || b[j]-b[temp] > midbase) {
					flag[i] = j-1;
					temp = j-1;
					break;
				}
				j++;
			}
		}
		flag[0] = 0;
		for(i = k; i >= 1; i--) {
			printf("%d", books[flag[i]]);
			for(j=flag[i]-1;j>flag[i-1];j--) {
                printf(" %d",books[j]);
            }
            if(i!=1) {
				printf(" / ");
            }
		}
		printf("\n");
	}
	return 0;
}

long long getbase(long long *b, int m, int k)
{
	long long mid, l, r;
	l = b[m] / k;
	r = b[m];
	while(l <= r) {
		mid = (l+r)/2;
		if(partion(b, mid, k, m)) {
			l = mid+1;
		} else {
			r = mid-1;
		}
	}
	return l;
}

int partion(long long *b, long long mid, int k, int m)
{
	int i, j, temp;
	j = 0;
	temp = 0;
	for(i = 0; i < k; i++) {
		while(1) {
			if(j > m || b[j]-b[temp] > mid) {
				temp = j-1;
				break;
			}
			j++;
		}
		if(j > m) {
			return 0;
		}
	}
	return 1;
}


【博士论文复现】【阻抗建模、验证扫频法】光伏并网逆变器扫频与稳定性分析(包含锁相环电流环)(Simulink仿真实现)内容概要:本文档围绕“博士论文复现”主题,重点介绍了光伏并网逆变器的阻抗建模与扫频法稳定性分析,涵盖锁相环和电流环的Simulink仿真实现。文档旨在通过完整的仿真资源和代码帮助科研人员复现相关技术细节,提升对新能源并网系统动态特性和稳定机制的理解。此外,文档还提供了大量其他科研方向的复现资源,包括微电网优化、机器学习、路径规划、信号处理、电力系统分析等,配套MATLAB/Simulink代码与模型,服务于多领域科研需求。; 适合人群:具备一定电力电子、自动控制或新能源背景的研究生、博士生及科研人员,熟悉MATLAB/Simulink环境,有志于复现高水平论文成果并开展创新研究。; 使用场景及目标:①复现光伏并网逆变器的阻抗建模与扫频分析过程,掌握其稳定性判据与仿真方法;②借鉴提供的丰富案例资源,支撑博士论文或期刊论文的仿真实验部分;③结合团队提供的算法与模型,快速搭建实验平台,提升科研效率。; 阅读建议:建议按文档目录顺序浏览,优先下载并运行配套仿真文件,结合理论学习与代码调试加深理解;重点关注锁相环与电流环的建模细节,同时可拓展学习其他复现案例以拓宽研究视野。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值