LA4850 - Installations

本文探讨了电信服务工程师的任务调度问题,通过定义任务的完成时间和截止期限之间的惩罚值来衡量任务超时的程度,并提出了一种算法来最小化两个最大惩罚值之和。
In the morning, service engineers in a telecom company receive a list of jobs which they must serve today. They install telephones, internet, ipTVs, etc and repair troubles with established facilities. A client requires a deadline when the requested job must be completed. But the engineers may not complete some jobs within their deadlines because of job overload. For each job, we consider, as a penalty of the engineer, the difference between the deadline and the completion time. It measures how long the job proceeds after its deadline. The problem is to find a schedule minimizing the sum of the penalties of the jobs with the two largest penalties.

A service engineer gets a list of jobs Ji with a serving time si and a deadline di. A job Ji needs time si, and if it is completed at time Ci, then the penalty of Ji is defined to be max{0, Ci - di}. For convenience, we assume that the time t when a job can be served is 0$ \le$t < $ \infty$ and si and di are given positive integers such that 0 < si$ \le$di. The goal is to find a schedule of jobs minimizing the sum of the penalties of the jobs with the two largest penalties.

For example, there are six jobs Ji with the pair (si, di) of the serving time si and the deadline di, i = 1,..., 6, where (s1, d1) = (1, 7), (s2, d2) = (4, 7), (s3, d3) = (2, 4), (s4, d4) = (2, 15), (s5, d5) = (3, 5), (s6, d6) = (3, 8). Then Figure 1 represents a schedule which minimizes the sum of the penalties of the jobs with the two largest penalties. The sum of the two largest penalties of an optimal schedule is that of the penalties of J2 and J6, namely 6 and 1, respectively, which is equal to 7 in this example.

\epsfbox{p4850.eps}

Figure 1. The optimal schedule of the example

Input 

Your program is to read from standard input. The input consists of T test cases. The number of test cases T is given on the first line of the input. The first line of each test case contains an integer n ( 1$ \le$n$ \le$500), the number of the given jobs. In the next n lines of each test case, the i-th line contains two integer numbers si and di, representing the serving time and the deadline of the job Ji, respectively, where 1$ \le$si$ \le$di$ \le$10, 000.

Output 

Your program is to write to standard output. Print exactly one line for each test case. The line contains the sum of the penalties of the jobs with the two largest penalties.

The following shows sample input and ouput for three test cases.

Sample Input 

3
6
1 7
4 7
2 4
2 15
3 5
3 8
7
2 17
2 11
3 4
3 20
1 20
4 7
5 14
10
2 5
2 9
5 10
3 11
3 4
4 21
1 7
2 9
2 11
2 23

Sample Output 

7
0

14

只想到最大惩罚值用贪心,不知道两个怎么搞,也是看了别人的题解,分析问题的思维好欠缺啊。
首先还是贪心,然后分三种情况讨论分析
1.所有惩罚值为0.答案就是0
2.有一个有惩罚值,答案就是该惩罚值。
3有两个以上的惩罚值,我们假设最大为max1,次大为max2,就会有两个下标为xb1,xb2.
会把任务划分成三段


我们试着移动任务:
(1)从1找一个任务移动到2执行,则xb2所对应的惩罚值不变,xb1所对应的惩罚值增加。
(2)从2找一个任务移动到3执行,则xb1所对应的惩罚值不变,xb2所对应的惩罚值增加。
(3)从1找一个任务移动到3执行,虽然最大惩罚值会增大,但是则xb2所对应的惩罚值和xb1所对应的惩罚值减小。也就说最大惩罚值增大,次大惩罚值有可能减小。总和也就有可能减小。分析可以发现,最好也就是移动任务到xb2后面第一个。
所以我们只要枚举(3)情况就可以了。

#include <iostream>
#include <stdio.h>
#include <cstring>
#include <algorithm>
#include <queue>
#include <map>
#include <cmath>
using namespace std;
typedef long long ll;
const int MAXN = 510;
int n;
struct node
{
    int s, d;
}g[MAXN];
bool cmp(node a, node b)
{
    return a.d<b.d;
}
int work()
{
    int ans;
    sort(g,g+n,cmp);
    int i, j, xb1=-1, xb2=-1, sum = 0, max1=0, max2=0;
    /*for(i=0; i<n; i++)
    {
        printf("%d %d\n",g[i].s,g[i].d);
    }*/
    for(i=0; i<n; i++)
    {
        sum += g[i].s;
        int temp = max(sum - g[i].d,0);
        if(temp>max1)
        {
            max2 = max1;
            max1 = temp;
            xb1 = xb2; xb2 = i;
        }else if(temp>max2)
        {
            max2 = temp;
            xb1 = xb2; xb2 = i;
        }
    }
    ans = max1 + max2;
    for(i=0; i<=xb1; i++) // 枚举移动的工作
    {
        //每次都要初始化
        sum = max1 = max2 = 0;
        for(j=0; j<n; j++)
        {
            if(j==i)continue;//跳过所选的工作
            sum += g[j].s;
            int temp = max(sum - g[j].d,0);
            if(temp>max1)
            {
                max2 = max1;
                max1 = temp;

            }else if(temp>max2)
            {
                max2 = temp;
            }
            if(j==xb2) //把移动的工作放入xb2后面
            {
                sum += g[i].s;
                int temp = max(sum - g[i].d,0);
                if(temp>max1)
                {
                    max2 = max1;
                    max1 = temp;

                }else if(temp>max2)
                {
                    max2 = temp;
                }
            }
        }
        //cout<<i<<" "<<max1+max2<<endl;
        ans = min(ans, max1 + max2); //选择最优解
    }
    return ans;
}
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        for(int i=0; i<n; i++)
        {
            scanf("%d%d",&g[i].s,&g[i].d);
        }
        printf("%d\n",work());
    }
    return 0;
}


本 PPT 介绍了制药厂房中供配电系统的总体概念与设计要点,内容包括: 洁净厂房的特点及其对供配电系统的特殊要求; 供配电设计的一般原则与依据的国家/行业标准; 从上级电网到工厂变电所、终端配电的总体结构与模块化设计思路; 供配电范围:动力配电、照明、通讯、接地、防雷与消防等; 动力配电中电压等级、接地系统形式(如 TN-S)、负荷等级与可靠性、UPS 配置等; 照明的电源方式、光源选择、安装方式、应急与备用照明要求; 通讯系统、监控系统在生产管理与消防中的作用; 接地与等电位连接、防雷等级与防雷措施; 消防设施及其专用供电(消防泵、排烟风机、消防控制室、应急照明等); 常见高压柜、动力柜、照明箱等配电设备案例及部分设计图纸示意; 公司已完成的典型项目案例。 1. 工程背景与总体框架 所属领域:制药厂房工程的公用工程系统,其中本 PPT 聚焦于供配电系统。 放在整个公用工程中的位置:与给排水、纯化水/注射用水、气体与热力、暖通空调、自动化控制等系统并列。 2. Part 01 供配电概述 2.1 洁净厂房的特点 空间密闭,结构复杂、走向曲折; 单相设备、仪器种类多,工艺设备昂贵、精密; 装修材料与工艺材料种类多,对尘埃、静电等更敏感。 这些特点决定了:供配电系统要安全可靠、减少积尘、便于清洁和维护。 2.2 供配电总则 供配电设计应满足: 可靠、经济、适用; 保障人身与财产安全; 便于安装与维护; 采用技术先进的设备与方案。 2.3 设计依据与规范 引用了大量俄语标准(ГОСТ、СНиП、SanPiN 等)以及国家、行业和地方规范,作为设计的法规基础文件,包括: 电气设备、接线、接地、电气安全; 建筑物电气装置、照明标准; 卫生与安全相关规范等。 3. Part 02 供配电总览 从电源系统整体结构进行总览: 上级:地方电网; 工厂变电所(10kV 配电装置、变压
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值