POJ1015---Jury Compromise

本文介绍了一种用于从候选者中挑选最公平陪审团成员的算法。该算法通过平衡辩护方和起诉方的利益来确保审判公正。通过动态规划方法实现,详细展示了算法流程及其代码实现。

Description
In Frobnia, a far-away country, the verdicts in court trials are determined by a jury consisting of members of the general public. Every time a trial is set to begin, a jury has to be selected, which is done as follows. First, several people are drawn randomly from the public. For each person in this pool, defence and prosecution assign a grade from 0 to 20 indicating their preference for this person. 0 means total dislike, 20 on the other hand means that this person is considered ideally suited for the jury.
Based on the grades of the two parties, the judge selects the jury. In order to ensure a fair trial, the tendencies of the jury to favour either defence or prosecution should be as balanced as possible. The jury therefore has to be chosen in a way that is satisfactory to both parties.
We will now make this more precise: given a pool of n potential jurors and two values di (the defence’s value) and pi (the prosecution’s value) for each potential juror i, you are to select a jury of m persons. If J is a subset of {1,…, n} with m elements, then D(J ) = sum(dk) k belong to J
and P(J) = sum(pk) k belong to J are the total values of this jury for defence and prosecution.
For an optimal jury J , the value |D(J) - P(J)| must be minimal. If there are several jurys with minimal |D(J) - P(J)|, one which maximizes D(J) + P(J) should be selected since the jury should be as ideal as possible for both parties.
You are to write a program that implements this jury selection process and chooses an optimal jury given a set of candidates.

Input
The input file contains several jury selection rounds. Each round starts with a line containing two integers n and m. n is the number of candidates and m the number of jury members.
These values will satisfy 1<=n<=200, 1<=m<=20 and of course m<=n. The following n lines contain the two integers pi and di for i = 1,…,n. A blank line separates each round from the next.
The file ends with a round that has n = m = 0.

Output
For each round output a line containing the number of the jury selection round (‘Jury #1’, ‘Jury #2’, etc.).
On the next line print the values D(J ) and P (J ) of your jury as shown below and on another line print the numbers of the m chosen candidates in ascending order. Output a blank before each individual candidate number.
Output an empty line after each test case.

Sample Input

4 2
1 2
2 3
4 1
6 2
0 0

Sample Output

Jury #1
Best jury has value 6 for prosecution and value 4 for defence:
2 3

Hint
If your solution is based on an inefficient algorithm, it may not execute in the allotted time.

Source
Southwestern European Regional Contest 1996

之前想的dp[i][j]表示前i个人里选出j个人的情况下最小的辩控差,但是由于绝对值的关系,这样是不满足最优子结构的

dp[i][j] 表示 选出i个人,辩控差为j的情况下,最大的辩控和
dp[i][j] = max (dp[i - 1][x] + sum[x]);
且cha[x] + x == j (cha[i]是第i个人的辩控差,sum[i]是第i个人的辩控和
用path[i][j] 记录 dp[i][j]里选中的人的编号,枚举第i个人,迭代回溯就可以判断这个人之前是否选过
辩控差可为负,所以加一个区间偏移量

/*************************************************************************
    > File Name: POJ1015.cpp
    > Author: ALex
    > Mail: zchao1995@gmail.com 
    > Created Time: 2015年02月15日 星期日 16时31分01秒
 ************************************************************************/

#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

const double pi = acos(-1);
const int inf = 0x3f3f3f3f;
const double eps = 1e-15;
typedef long long LL;
typedef pair <int, int> PLL;

int dp[25][1010];
int path[25][1010];
int d[222], p[222];
int ans[22];
int sum[222], cha[222];

bool judge (int i, int j, int k)
{
    while (j > 0 && path[j][k] != i)
    {
        int x = path[j][k];
        --j;
        k -= cha[x];
    }
    return !j;
}

int main ()
{
    int n, m;
    int icase = 1;
    while (~scanf("%d%d", &n, &m))
    {
        if (!n && !m)
        {
            break;
        }
        memset (dp, -1, sizeof (dp));
        memset (path, 0, sizeof(path));
        for (int i = 1; i <= n; ++i)
        {
            scanf("%d%d", &p[i], &d[i]);
            sum[i] = p[i] + d[i];
            cha[i] = p[i] - d[i];
        }
        int fix = m * 20;
        dp[0][fix] = 0;
        for (int j = 1; j <= m; ++j)
        {
            for (int k = 0; k <= 2 * fix; ++k)
            {
                if (dp[j - 1][k] >= 0)
                {
                    for (int i = 1; i <= n; ++i)
                    {
                        if (dp[j][k + cha[i]] < dp[j - 1][k] + sum[i])
                        {
                            if (!judge (i, j - 1, k))
                            {
                                continue;
                            }
                            dp[j][k + cha[i]] = dp[j - 1][k] + sum[i];
                            path[j][k + cha[i]] = i;
                        }
                    }
                }
            }
        }
        int x;
        for (int k = 0; k <= fix; ++k)
        {
            if (dp[m][fix - k] >= 0 || dp[m][fix + k] >= 0)
            {
                x = k;
                break;
            }
        }
        int div = dp[m][fix - x] > dp[m][fix + x] ? fix - x : fix + x;
        printf("Jury #%d\n", icase++);
        int x1 = (dp[m][div] + div - fix) / 2;
        int x2 = (dp[m][div] - div + fix) / 2;
        printf("Best jury has value %d for prosecution and value %d for defence:\n", x1, x2);
        int cnt = m;
        while (path[m][div] > 0)
        {
            ans[m] = path[m][div];
            div -= cha[path[m][div]];
            --m;
        }
        sort (ans + 1, ans + cnt + 1);
        for (int i = 1; i <= cnt; ++i)
        {
            printf(" %d", ans[i]);
        }
        printf("\n");
    }
    return 0;
}
【SCI复现】含可再生能源与储能的区域微电网最优运行:应对不确定性的解鲁棒性与非预见性研究(Matlab代码实现)内容概要:本文围绕含可再生能源与储能的区域微电网最优运行展开研究,重点探讨应对不确定性的解鲁棒性与非预见性策略,通过Matlab代码实现SCI论文复现。研究涵盖多阶段鲁棒调度模型、机会约束规划、需求响应机制及储能系统优化配置,结合风电、光伏等可再生能源出力的不确定性建模,提出兼顾系统经济性与鲁棒性的优化运行方案。文中详细展示了模型构建、算法设计(如C&CG算法、大M法)及仿真验证全过程,适用于微电网能量管理、电力系统优化调度等领域的科研与工程实践。; 适合人群:具备一定电力系统、优化理论和Matlab编程基础的研究生、科研人员及从事微电网、能源管理相关工作的工程技术人员。; 使用场景及目标:①复现SCI级微电网鲁棒优化研究成果,掌握应对风光负荷不确定性的建模与求解方法;②深入理解两阶段鲁棒优化、分布鲁棒优化、机会约束规划等先进优化方法在能源系统中的实际应用;③为撰写高水平学术论文或开展相关课题研究提供代码参考和技术支持。; 阅读建议:建议读者结合文档提供的Matlab代码逐模块学习,重点关注不确定性建模、鲁棒优化模型构建与求解流程,并尝试在不同场景下调试与扩展代码,以深化对微电网优化运行机制的理解。
个人防护装备实例分割数据集 一、基础信息 数据集名称:个人防护装备实例分割数据集 图片数量: 训练集:4,524张图片 分类类别: - Gloves(手套):工作人员佩戴的手部防护装备。 - Helmet(安全帽):头部防护装备。 - No-Gloves(未戴手套):未佩戴手部防护的状态。 - No-Helmet(未戴安全帽):未佩戴头部防护的状态。 - No-Shoes(未穿安全鞋):未佩戴足部防护的状态。 - No-Vest(未穿安全背心):未佩戴身体防护的状态。 - Shoes(安全鞋):足部防护装备。 - Vest(安全背心):身体防护装备。 标注格式:YOLO格式,包含实例分割的多边形坐标和类别标签,适用于实例分割任务。 数据格式:来源于实际场景图像,适用于计算机视觉模型训练。 二、适用场景 工作场所安全监控系统开发:数据集支持实例分割任务,帮助构建能够自动识别工作人员个人防护装备穿戴状态的AI模型,提升工作环境安全性。 建筑与工业安全检查:集成至监控系统,实时检测PPE穿戴情况,预防安全事故,确保合规性。 学术研究与创新:支持计算机视觉在职业安全领域的应用研究,促进AI与安全工程的结合。 培训与教育:可用于安全培训课程,演示PPE识别技术,增强员工安全意识。 三、数据集优势 精准标注与多样性:每个实例均用多边形精确标注,确保分割边界准确;覆盖多种PPE物品及未穿戴状态,增加模型鲁棒性。 场景丰富:数据来源于多样环境,提升模型在不同场景下的泛化能力。 任务适配性强:标注兼容主流深度学习框架(如YOLO),可直接用于实例分割模型开发,支持目标检测和分割任务。 实用价值高:专注于工作场所安全,为自动化的PPE检测提供可靠数据支撑,有助于减少工伤事故。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值