【差分约束】poj1275Cashier Employment

本文深入探讨了一个经典的差分约束问题,通过设定特定的工作安排和需求,利用数学模型和算法,解决超市收银员最优配置的问题。文章详细介绍了如何建立约束关系,使用枚举法确定最小雇员数量,并提供了实现代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

比较经典的差分约束

Description

A supermarket in Tehran is open 24 hours a day every day and needs a number of cashiers to fit its need. The supermarket manager has hired you to help him, solve his problem. The problem is that the supermarket needs different number of cashiers at different times of each day (for example, a few cashiers after midnight, and many in the afternoon) to provide good service to its customers, and he wants to hire the least number of cashiers for this job. 

The manager has provided you with the least number of cashiers needed for every one-hour slot of the day. This data is given as R(0), R(1), ..., R(23): R(0) represents the least number of cashiers needed from midnight to 1:00 A.M., R(1) shows this number for duration of 1:00 A.M. to 2:00 A.M., and so on. Note that these numbers are the same every day. There are N qualified applicants for this job. Each applicant i works non-stop once each 24 hours in a shift of exactly 8 hours starting from a specified hour, say ti (0 <= ti <= 23), exactly from the start of the hour mentioned. That is, if the ith applicant is hired, he/she will work starting from ti o'clock sharp for 8 hours. Cashiers do not replace one another and work exactly as scheduled, and there are enough cash registers and counters for those who are hired. 

You are to write a program to read the R(i) 's for i=0..23 and ti 's for i=1..N that are all, non-negative integer numbers and compute the least number of cashiers needed to be employed to meet the mentioned constraints. Note that there can be more cashiers than the least number needed for a specific slot. 

Input

The first line of input is the number of test cases for this problem (at most 20). Each test case starts with 24 integer numbers representing the R(0), R(1), ..., R(23) in one line (R(i) can be at most 1000). Then there is N, number of applicants in another line (0 <= N <= 1000), after which come N lines each containing one ti (0 <= ti <= 23). There are no blank lines between test cases.

Output

For each test case, the output should be written in one line, which is the least number of cashiers needed. 
If there is no solution for the test case, you should write No Solution for that case. 

Sample Input

1
1 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
5
0
23
22
1
10

Sample Output

1

题目大意

直接挂loj的翻译算了……

题目分析

算是差分约束类型有难度并且挺经典的题目。

设$s_i$为$i$时刻能够开始工作的人数;$x_i$为$i$时刻实际雇佣的人数。于是有$x_i≤num_i$。设$a_i$为$i$时刻至少需要工作的人数。有:

$x_{i-7}+x_{i-6}+...+x_{i-1}+x_i≥a_i$

设$t_i=x_1+x_2+...+x_i$,则得到

$0≤t_i-t_{i-1}≤s_i,0≤i≤23,$

$t_i-t_{i-8}≥a_i,8≤i≤23,$

$t_{23}+t_i-t_{i+16}≥a_i,0≤i≤7$

那么在建出约束关系之后,就是枚举$t_{23}$.

之后就是处理的细节需要注意一下。

 

 1 #include<cstdio>
 2 #include<cctype>
 3 #include<cstring>
 4 const int maxn = 103;
 5 const int maxm = 303;
 6 
 7 struct Edge
 8 {
 9     int y,val;
10     Edge(int a=0, int b=0):y(a),val(b) {}
11 }edges[maxm];
12 int T,n,ans,a[35],s[maxn],dis[maxn];
13 int edgeTot,head[maxn],nxt[maxm];
14 bool vis[maxn];
15 
16 int read()
17 {
18     char ch = getchar();
19     int num = 0;
20     bool fl = 0;
21     for (; !isdigit(ch); ch=getchar())
22         if (ch=='-') fl = 1;
23     for (; isdigit(ch); ch=getchar())
24         num = (num<<1)+(num<<3)+ch-48;
25     if (fl) num = -num;
26     return num;
27 }
28 void init()
29 {
30     edgeTot = 0;
31     memset(dis, -0x3f3f3f3f, sizeof dis);
32 //    memset(dis, 0, sizeof dis);
33     memset(vis, 0, sizeof vis);
34     memset(head, -1, sizeof head);
35 }
36 void addedge(int u, int v, int c)
37 {
38     edges[++edgeTot] = Edge(v, c), nxt[edgeTot] = head[u], head[u] = edgeTot;
39 }
40 bool dfs(int x)
41 {
42     vis[x] = 1;
43     for (int i=head[x]; i!=-1; i=nxt[i])
44     {
45         int v = edges[i].y, w = edges[i].val;
46         if (dis[v] < dis[x]+w){
47             dis[v] = dis[x]+w;
48             if (vis[v]||dfs(v)) return 1;
49         }
50     }
51     vis[x] = 0;
52     return 0;
53 }
54 bool check(int w)
55 {
56     init(), dis[0] = 0;
57 //    for (int i=1; i<=23; i++) addedge(i-1, i, 0);addedge(23, 0, 0);
58 //    for (int i=1; i<=23; i++) addedge(i, i-1, -w);addedge(0, 23, -w);
59     for (int i=1; i<=24; i++) addedge(i-1, i, 0), addedge(i, i-1, -s[i]);
60 //    for (int i=8; i<=23; i++) addedge(i-8, i, a[i]);
61 //    for (int i=0; i<=7; i++) addedge(i+16, i, s[i]-w);    //注意细节处理
62     for (int i=8; i<=24; i++) addedge(i-8, i, a[i]);
63     for (int i=1; i<=8; i++) addedge(i+16, i, a[i]-w);
64     addedge(0, 24, w);
65     return dfs(0);
66 }
67 int main()
68 {
69     T = read();
70     while (T--)
71     {
72         memset(s, 0, sizeof s);
73         for (int i=1; i<=24; i++) a[i] = read();
74         n = read(), ans = -1;
75         for (int i=1; i<=n; i++) s[read()+1]++;
76         for (int i=0; i<=n; i++)
77             if (!check(i)){
78                 ans = i;
79                 break;
80             }
81         if (ans==-1) puts("No Solution");
82         else printf("%d\n",ans);
83     }
84     return 0;
85 }

 

 

 

 

END

转载于:https://www.cnblogs.com/antiquality/p/9858318.html

内容概要:本文围绕直流微电网中带有恒功率负载(CPL)的DC/DC升压转换器的稳定控制问题展开研究,提出了一种复合预设性能控制策略。首先,通过精确反馈线性化技术将非线性不确定的DC转换器系统转化为Brunovsky标准型,然后利用非线性扰动观测器评估负载功率的动态变化和输出电压的调节精度。基于反步设计方法,设计了具有预设性能的复合非线性控制器,确保输出电压跟踪误差始终在预定义误差范围内。文章还对比了多种DC/DC转换器控制技术如脉冲调整技术、反馈线性化、滑模控制(SMC)、主动阻尼法和基于无源性的控制,并分析了它们的优缺点。最后,通过数值仿真验证了所提控制器的有效性和优越性。 适合人群:从事电力电子、自动控制领域研究的学者和工程师,以及对先进控制算法感兴趣的研究生及以上学历人员。 使用场景及目标:①适用于需要精确控制输出电压并处理恒功率负载的应用场景;②旨在实现快速稳定的电压跟踪,同时保证系统的鲁棒性和抗干扰能力;③为DC微电网中的功率转换系统提供兼顾瞬态性能和稳态精度的解决方案。 其他说明:文中不仅提供了详细的理论推导和算法实现,还通过Python代码演示了控制策略的具体实现过程,便于读者理解和实践。此外,文章还讨论了不同控制方法的特点和适用范围,为实际工程项目提供了有价值的参考。
内容概要:该论文介绍了一种名为偏振敏感强度衍射断层扫描(PS-IDT)的新型无参考三维偏振敏感计算成像技术。PS-IDT通过多角度圆偏振光照射样品,利用矢量多层光束传播模型(MSBP)和梯度下降算法迭代重建样品的三维各向异性分布。该技术无需干涉参考光或机械扫描,能够处理多重散射样品,并通过强度测量实现3D成像。文中展示了对马铃薯淀粉颗粒和缓步类动物等样品的成功成像实验,并提供了Python代码实现,包括系统初始化、前向传播、多层传播、重建算法以及数字体模验证等模块。 适用人群:具备一定光学成像和编程基础的研究人员,尤其是从事生物医学成像、材料科学成像领域的科研工作者。 使用场景及目标:①研究复杂散射样品(如生物组织、复合材料)的三维各向异性结构;②开发新型偏振敏感成像系统,提高成像分辨率和对比度;③验证和优化计算成像算法,应用于实际样品的高精度成像。 其他说明:PS-IDT技术相比传统偏振成像方法具有明显优势,如无需干涉装置、无需机械扫描、可处理多重散射等。然而,该技术也面临计算复杂度高、需要多角度数据采集等挑战。文中还提出了改进方向,如采用更高数值孔径(NA)物镜、引入深度学习超分辨率技术等,以进一步提升成像质量和效率。此外,文中提供的Python代码框架为研究人员提供了实用的工具,便于理解和应用该技术。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值