zoukankan      html  css  js  c++  java
  • TC609 DIV1 (500)

    Problem Statement

         We have balls of K different colors. The colors are numbered 0 through K-1, and the number of balls of color i is X[i]. We want to divide the balls into as few packages as possible. Each package must contain between 1 and K balls, inclusive. Additionally, each package must be either a "normal set" (all balls in the package have the same color), or a "variety set" (no two balls have the same color).
    You are given the int K. You are also given ints A, B, C, and D. Use these to generate the array X using the following pseudocode:
    X[0] = A
    for i = 1 to K-1:
        X[i] = (X[i-1] * B + C) % D + 1

    Compute and return the smallest possible number of packages.

    Definition

        
    Class: PackingBallsDiv1
    Method: minPacks
    Parameters: int, int, int, int, int
    Returns: int
    Method signature: int minPacks(int K, int A, int B, int C, int D)
    (be sure your method is public)

    Limits

        
    Time limit (s): 2.000
    Memory limit (MB): 256

    Notes

    - You can assume that the answer will fit into a signed 32-bit integer.

    Constraints

    - K will be between 1 and 100,000, inclusive.
    - B, C and D will be between 1 and 1,000,000,000, inclusive.
    - A will be between 1 and D, inclusive.

    Examples

    0)  
        
    3
    4
    2
    5
    6
    Returns: 4
    There are three colors of balls. Using the pseudocode in the problem statement, we can compute that X[0]=4, X[1]=2, and X[2]=4. As there are 10 balls and we can only put at most 3 into each package, we need at least 4 packages. One possible solution with 4 packages is {0,1,2}, {0,0}, {0,1}, and {2,2,2}. (That is, the first package contains one ball of each color, the second package contains two balls of color 0, and so on.)
    1)  
        
    1
    58
    23
    39
    93
    Returns: 58
    All the balls have the same color, and each package can only contain one ball. Thus, the number of packages is the same as the number of balls.
    2)  
        
    23
    10988
    5573
    4384
    100007
    Returns: 47743
     
    3)  
        
    100000
    123456789
    234567890
    345678901
    1000000000
    Returns: 331988732
    Watch out for integer overflow when generating X.

    郁闷了 记得昨天就是这思路写的 硬是没过去样例 今天打了一遍直接A了

    尽量的让每个背包装满 先把除得进的加上 再选一个最优的方案放余数  方案两种 要么全相同要么全不同 选一个最优的

     1 #include <iostream>
     2 #include<cstdio>
     3 #include<cstring>
     4 #include<algorithm>
     5 #include<stdlib.h>
     6 #include<cmath>
     7 using namespace std;
     8 #define LL long long
     9 #define N 100010
    10 #define INF 1e9
    11 LL x[N];
    12 int f[N];
    13 class PackingBallsDiv1
    14 {
    15     public :
    16     int minPacks(int K, int A, int B, int C, int D)
    17     {
    18         int i;
    19         x[0] = A;
    20         for(i = 1; i < K ; i++)
    21         x[i] = (x[i-1]*B+C)%D+1;
    22         LL s=0;
    23         for(i = 0; i < K ; i++)
    24         {
    25             s+=x[i]/K;
    26             x[i] = x[i]%K;f[x[i]]++;
    27         }
    28         LL ans = INF;
    29         sort(x,x+K);
    30         for(i = 0; i < K ; i++)
    31         {
    32             ans = min(ans,x[i]+s+K-i-1);
    33         }
    34         return ans;
    35     }
    36 };
    View Code
  • 相关阅读:
    C++如何在Dialog和View中显示梯度背景颜色
    C++MFC的关键类(View,Application,Frame,Document等等)之间访问方法列表
    C++深入分析MFC文档视图结构(项目实践)
    C++如何修改SDI程序的默认背景颜色
    BAPI使用HR_INFOTYPE_OPERATION函数批量导入HR信息纪录代码样例(0759信息类型)
    C++在单文档的应用程序增加多个视图
    SD定价过程的16个字段的作用说明
    HR上载信息类型的长文本的样例代码
    C++在工具条中加入组合框控件
    C++如何锁定splitter窗口
  • 原文地址:https://www.cnblogs.com/shangyu/p/3551788.html
Copyright © 2011-2022 走看看