zoukankan      html  css  js  c++  java
  • ZOJ 2343 Robbers



    Robbers

    Time Limit: 5 Seconds      Memory Limit: 32768 KB      Special Judge

    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



    Author: Andrew Stankevich
    Source: Andrew Stankevich's Contest #2

    按比例放大xi,剩下的coin尽量分到可以使绝对值变小的强盗的手里。。。。。。。

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <cmath>

    using namespace std;

    int main()
    {
        int T;
        scanf("%d",&T);
    while(T--)
    {
        int n,M,Y,a[1100],k[1100],res=0;
        double temp[1100];
        scanf("%d%d%d",&n,&M,&Y);
        for(int i=0;i<n;i++)
        {
            scanf("%d",&a);
            k=M/Y*a;
            temp=fabs(a*1.0/Y-k*1.0/M);
        }

        res=M-M/Y*Y;

        while(res--)
        {
            double minn=0x3f3f3f3f;
            int pos=-1;
            for(int i=0;i<n;i++)
            {
                if(minn>fabs(a*1.0/Y-(k*1.0+1)/M)-temp)
                {
                    minn=fabs(a*1.0/Y-(k*1.0+1)/M)-temp;
                    pos=i;
                }
            }
            k[pos]=k[pos]+1;
            temp[pos]=fabs(a[pos]*1.0/Y-k[pos]*1.0/M);
        }

        for(int i=0;i<n;i++)
            printf("%d ",k);
        putchar(10);
    }
        return 0;
    }



  • 相关阅读:
    Django的是如何工作的
    Robot Framework自动化测试(五)--- 开发系统关键字
    Swarm 如何存储数据?- 每天5分钟玩转 Docker 容器技术(103)
    如何滚动更新 Service?- 每天5分钟玩转 Docker 容器技术(102)
    Service 之间如何通信?- 每天5分钟玩转 Docker 容器技术(101)
    神奇的 routing mesh
    如何访问 Service?- 每天5分钟玩转 Docker 容器技术(99)
    Swarm 如何实现 Failover?- 每天5分钟玩转 Docker 容器技术(98)
    如何实现 Service 伸缩?- 每天5分钟玩转 Docker 容器技术(97)
    运行第一个 Service
  • 原文地址:https://www.cnblogs.com/CKboss/p/3350925.html
Copyright © 2011-2022 走看看