UVA 1422 - Processor (二分+贪心+优先队列)

本文探讨了如何通过调整处理器速度来优化能耗效率的问题。提出了一种利用优先队列和二分查找的方法来找到最小化最大处理器速度的解决方案。

An ``early adopter" Mr. Kim bought one of the latest notebooks which has a speed-controlled processor. The processor is able to operate at variable speed. But the higher the speed, the higher the power consumption is. So, to execute a set of programs, adjusting the speed of the processor dynamically results in energy-efficient schedules. We are concerned in a schedule to minimize the maximum speed of the processor.

The processor shall execute a set of programs and each programPiis given having a starting timeri, a deadlinedi, and workwi. When the processor executes the programs, for each programPi, the workwishould be done on the processor within the interval[ri,di]to completePi. Also, the processor does not have to execute a program in a contiguous interval, that is, it can interrupt the currently running program and later resume it at the interrupted point. It is assumed thatri,di, andwiare given positive integers. Recall that the processor can execute the programs at variable speed. If the processor runs the programPiwith workwiat a constant speeds,then it takes$ {\frac{​{w_{i}}}{​{s}}}$time to completePi. We also assume that the available speeds are positive integers, that is, the processor operates only at integer points of speed. The speed is unbounded and the processor may operate at sufficiently large speeds to complete all the programs. The processor should complete all the given programs and the goal is to find a schedule minimizing the maximum of the speeds at which the processor operates.

For example, there are five programsPiwith the interval[ri,di]and workwi,i= 1,..., 5, where[r1,d1] = [1, 4],[r2,d2] = [3, 6],[r3,d3] = [4, 5],[r4,d4] = [4, 7],[r5,d5] = [5, 8]andw1= 2,w2= 3,w3= 2,w4= 2,w5= 1. Then the Figure 1 represents a schedule which minimizes the maximum speed at which the processor operates. The maximum speed is 2 in this example.

=6in\epsfbox{p4254.eps}

Input

Your program is to read from standard input. The input consists ofTtest cases. The number of test casesT(1$ \le$T$ \le$20)is given on the first line of the input. The first line of each test case contains an integern(1$ \le$n$ \le$10, 000), the number of given programs which the processor shall execute. In the nextnlines of each test case, thei-th line contain three integer numbersri,di, andwi, representing the starting time, the deadline, and the work of the programPi, respectively, where1$ \le$ri<di$ \le$20, 000,1$ \le$wi$ \le$1, 000.

Output

Your program is to write to standard output. Print exactly one line for each test case. The line contains the maximum speed of a schedule minimizing the maximum speed at which the processor operates to complete all the given programs.

Sample Input

3 
5 
1 4 2 
3 6 3 
4 5 2 
4 7 2 
5 8 1 
6 
1 7 25 
4 8 10 
7 10 5 
8 11 5 
10 13 10 
11 13 5 
8 
15 18 10 
20 24 16 
8 15 33 
11 14 14 
1 6 16 
16 19 12 
3 5 12 
22 25 10

Sample Output

2 
5 
7

题意:给定n个任务,每个任务必须在时间【R,D]内完成,每个任务工作量为W,问最小完成速率使得所有工作完成。

思路:二分答案,然后进行judge,判断的时候利用优先队列,由于时间只有20000,去枚举每个单位时间,看要给分配个那个任务,这步利用优先队列,按d越小越先出队,因为d越小肯定要越快完成越好。

代码:

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <queue>
using namespace std;

const int N = 10005;

int t, n;
struct Work {
    double r, d, w;
    friend bool operator < (Work a, Work b) {
	return a.d > b.d;
    }
} work[N]; 

bool cmp(Work a, Work b) {
    return a.r < b.r;
}

void init() {
    scanf("%d", &n);
    for (int i = 0; i < n; i ++)
	scanf("%lf%lf%lf", &work[i].r, &work[i].d, &work[i].w);
    sort(work, work + n, cmp);
}

bool judge(int mid) {
    priority_queue<Work>Q;
    int wn = 0;
    for (int i = 1; i <= 20000; i ++) {
	int sum = mid;
	while (work[wn].r < i && wn != n) Q.push(work[wn++]);
	while (sum != 0 && !Q.empty()) {
	    Work save = Q.top(); Q.pop();
	    if (i > save.d) return false;
	    if (save.w > sum) {
		save.w -= sum;
		sum = 0;
		Q.push(save);
	    }
	    else {
		sum -= save.w;
	    }
	}
	if (wn == n && Q.empty()) break;
    }
    if (wn == n && Q.empty())
	return true;
    return false;
}

int solve() {
    int l = 0, r = 10000000, mid;
    while (l < r) {
	if (r - l == 1) break;
	mid = (l + r)>>1;
	if (!judge(mid)) l = mid;
	else r = mid;
    }
    return r;
}

int main() {
    scanf("%d", &t);
    while (t--) {
	init();
	printf("%d\n", solve());
    }
    return 0;
}



基于数据驱动的 Koopman 算子的递归神经网络模型线性化,用于纳米定位系统的预测控制研究(Matlab代码实现)内容概要:本文围绕“基于数据驱动的Koopman算子的递归神经网络模型线性化”展开,旨在研究纳米定位系统的预测控制方法。通过结合数据驱动技术与Koopman算子理论,将非线性系统动态近似为高维线性系统,进而利用递归神经网络(RNN)建模并实现系统行为的精确预测。文中详细阐述了模型构建流程、线性化策略及在预测控制中的集成应用,并提供了完整的Matlab代码实现,便于科研人员复现实验、优化算法并拓展至其他精密控制系统。该方法有效提升了纳米级定位系统的控制精度与动态响应性能。; 适合人群:具备自动控制、机器学习或信号处理背景,熟悉Matlab编程,从事精密仪器控制、智能制造或先进控制算法研究的研究生、科研人员及工程技术人员。; 使用场景及目标:①实现非线性动态系统的数据驱动线性化建模;②提升纳米定位平台的轨迹跟踪与预测控制性能;③为高精度控制系统提供可复现的Koopman-RNN融合解决方案; 阅读建议:建议结合Matlab代码逐段理解算法实现细节,重点关注Koopman观测矩阵构造、RNN训练流程与模型预测控制器(MPC)的集成方式,鼓励在实际硬件平台上验证并调整参数以适应具体应用场景。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值