文章标题 Robbers

N robbers have robbed the bank. As the result of their crime they chanced to get M golden coins. Before the robbery the band has made an agreement that after the robbery i-th gangster would get Xi=Y of all money gained. However, it turned out that M may be not divisible by Y.

The problem which now should be solved by robbers is what to do with the coins. They would like to share them fairly. Let us suppose that i-th robber would get Ki coins. In this case unfairness of this fact is |Xi/Y - Ki/M|. The total unfairness is the sum of all particular unfairnesses. Your task as the leader of the gang is to spread money among robbers in such a way that the total unfairness is minimized.

This problem contains multiple test cases!

The first line of a multiple input is an integer N, then a blank line followed by N input blocks. Each input block is in the format indicated in the problem description. There is a blank line between input blocks.

The output format consists of N output blocks. There is a blank line between output blocks.

Input
The first line of the input file contains numbers N, M and Y (1 <= N <= 1000, 1 <= M, Y <= 10000). N integer numbers follow - Xi (1 <= Xi <= 10000, sum of all Xi is Y).

Output
Output N integer numbers - Ki (sum of all Ki must be M), so that the total unfairness is minimal.

Sample Input
1

3 10 4
1 1 2

Sample Output
2 3 5
先求出double x=M/Y的值,按比例算出b[i]=a[i]*x,将b[i]分成整数和小数两部分,按整数部分得出M中金币还剩多少,将小数部分排序,小数部分大的先加加,直到剩余金币为0

#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
struct node
{
    int iden,x;
    double y;
}z[1009];
int a[1009];
double b[1009];
double cmp1(node a,node b)
{
    return a.y>b.y;
}
int cmp(node m,node n)
{
    return m.iden<n.iden;
}
int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        int N,M,Y;
        scanf("%d%d%d",&N,&M,&Y);
        int i;
        for(i=0;i<N;i++)
            scanf("%d",&a[i]);
        double k=double(M)/Y;
        int sum=0;
        for(i=0;i<N;i++)
        {
            b[i]=a[i]*k;
            z[i].iden=i;
            z[i].x=int(b[i]);
            z[i].y=b[i]-z[i].x;
            sum+=z[i].x;
        }
        sum=M-sum;
        sort(z,z+N,cmp1);
        for(i=0;i<N;i++)
        {
            if(sum)
            {
                z[i].x++;
                sum--;
            }
        }
        sort(z,z+N,cmp);
        for(i=0;i<N-1;i++)
            printf("%d ",z[i].x);
        printf("%d\n",z[N-1].x);
        if(T)
            printf("\n");
    }
}
内容概要:本文档为《软件设计师资料净化与分析报告(汇总)》,系统整理了软件设计师考试涉及的核心知识点及历年试题分析,涵盖计算机系统基础、操作系统、数据库、软件工程、网络与信息安全、程序设计语言、知识产权及计算机专业英语等多个模块。文档不仅包含各知识点的理论讲解,如CPU结构、海明码校验、虚拟存储器、PV操作、页式存储管理、关系范式、设计模式等,还结合真题解析强化理解,并提供了大量案例分析与算法实现,如数据流图、E-R图设计、排序算法、策略模式、备忘录模式等,全面覆盖软件设计师考试的上午选择题与下午案例分析题的考核重点。; 适合人群:准备参加全国计算机技术与软件专业技术资格(水平)考试中“软件设计师”科目的考生,尤其适合有一定计算机基础、正在系统复习备考的中级技术人员。; 使用场景及目标:①系统梳理软件设计师考试大纲要求的知识体系;②通过真题解析掌握高频考点与解题思路;③强化对操作系统、数据库、软件工程等核心模块的理解与应用能力;④提升对设计模式、算法设计与程序语言机制的综合运用水平。; 阅读建议:建议结合考试大纲,分模块逐步学习,重点掌握各章节的知识点归纳与真题解析部分,对于案例分析题应动手练习数据流图、E-R图绘制及代码填空,算法部分应理解分治、动态规划等思想,并通过反复练习巩固记忆,全面提升应试能力。
【完美复现】面向配电网韧性提升的移动储能预布局与动态调度策略【IEEE33节点】(Matlab代码实现)内容概要:本文介绍了基于IEEE33节点的配电网韧性提升方法,重点研究了移动储能系统的预布局与动态调度策略。通过Matlab代码实现,提出了一种结合预配置和动态调度的两阶段优化模型,旨在应对电网故障或极端事件时快速恢复供电能力。文中采用了多种智能优化算法(如PSO、MPSO、TACPSO、SOA、GA等)进行对比分析,验证所提策略的有效性和优越性。研究不仅关注移动储能单元的初始部署位置,还深入探讨其在故障发生后的动态路径规划与电力支援过程,从而全面提升配电网的韧性水平。; 适合人群:具备电力系统基础知识和Matlab编程能力的研究生、科研人员及从事智能电网、能源系统优化等相关领域的工程技术人员。; 使用场景及目标:①用于科研复现,特别是IEEE顶刊或SCI一区论文中关于配电网韧性、应急电源调度的研究;②支撑电力系统在灾害或故障条件下的恢复力优化设计,提升实际电网应对突发事件的能力;③为移动储能系统在智能配电网中的应用提供理论依据和技术支持。; 阅读建议:建议读者结合提供的Matlab代码逐模块分析,重点关注目标函数建模、约束条件设置以及智能算法的实现细节。同时推荐参考文中提及的MPS预配置与动态调度上下两部分,系统掌握完整的技术路线,并可通过替换不同算法或测试系统进一步拓展研究。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值