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了

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

 #include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<cmath>
using namespace std;
#define LL long long
#define N 100010
#define INF 1e9
LL x[N];
int f[N];
class PackingBallsDiv1
{
public :
int minPacks(int K, int A, int B, int C, int D)
{
int i;
x[] = A;
for(i = ; i < K ; i++)
x[i] = (x[i-]*B+C)%D+;
LL s=;
for(i = ; i < K ; i++)
{
s+=x[i]/K;
x[i] = x[i]%K;f[x[i]]++;
}
LL ans = INF;
sort(x,x+K);
for(i = ; i < K ; i++)
{
ans = min(ans,x[i]+s+K-i-);
}
return ans;
}
};

TC609 DIV1 (500)的更多相关文章

  1. 接口平台经常报server internal error(500)错误

    查询日志,发现连接mysql报错,web页面显示server internal error(500) 解决方法:重启mysql服务器 systemctl start mysqld #安装mysql # ...

  2. Cookie保存中文用户名报错(500)

    在用Cookie保存用户名时候,当用户名是中文的时候服务器报错了. HTTP Status 500 - An exception occurred processing JSP page /dolog ...

  3. php语法错误导致服务器错误(500)解决

    PHP编码出错不提示,而是提示500错误,这对于开发来说,是很不方便的.下面讲解如何开启错误提示步骤: 1. 打开php.ini文件.以我的ubuntu为例,这个文件在: /etc/php5/apac ...

  4. Tyvj P1015 公路骑 (DP)

     叙述性说明 Description 一个特殊的单行道都在每公里公交车站.们乘坐汽车的公里使来付费. 比如例子的第一行就是一个费用的单子. 没有一辆车子行驶超过10公里.一个顾客打算行驶n公里(1 ...

  5. 使用Visual Studio Code开发Asp.Net Core WebApi学习笔记(二)-- Web Api Demo

    在上一篇里,我已经建立了一个简单的Web-Demo应用程序.这一篇将记录将此Demo程序改造成一个Web Api应用程序. 一.添加ASP.NET Core MVC包 1. 在project.json ...

  6. 【PTA 天梯赛】L2-028 秀恩爱分得快(模拟)

    古人云:秀恩爱,分得快. 互联网上每天都有大量人发布大量照片,我们通过分析这些照片,可以分析人与人之间的亲密度.如果一张照片上出现了 K 个人,这些人两两间的亲密度就被定义为 1/K.任意两个人如果同 ...

  7. 微信js分享朋友圈(二)

    近期又用到微信分享的功能了.虽然不是第一次用了,依然我又有幸踩到了一个坑,所以分享一下吧. 根据微信sdk写的代码一步步很顺利,但是后面就是获取微信返回的分享结果的回调的时候IOS老是有问题,然后就网 ...

  8. (day44)前端、HTTP、HTML

    目录 一.什么是前端 二.web服务 (一)流程 (二)请求方式 (1)get请求 (2)post请求 三.HTTP协议 (一)什么是HTTP协议 (二)四大特性 (三)数据格式 (1)请求格式 (2 ...

  9. 基于Netty的RPC架构学习笔记(五):netty线程模型源码分析(二)

    文章目录 小技巧(如何看开源框架的源码) 源码解析 阅读源码技巧 打印查看 通过打断点调试 查看调用栈 小技巧(如何看开源框架的源码) 一断点 二打印 三看调用栈 四搜索 源码解析 //设置nioso ...

随机推荐

  1. 一个关于MYSQL IFNULL的用法

    select a.receiveID,(a.num - IFNULL(b.num,0)) as num from (SELECT num,receiveID from dog_giftnumrecor ...

  2. mac 通过 终端 ssh 远程连接 centos 服务器

    mac 通过 终端 ssh 远程连接 centos 服务器 在终端下输入 ssh -l root 204.74.*.*      就可以连接了,这是端口没变的情况,还是原来的22 ssh -p 448 ...

  3. hdu4183往返经过至多每一个点一次/最大流

    题意:从s到t,每一个点有f值,仅仅能从f值小的到大的.到T后回来.仅仅能从f值大的到 小的,求可行否. 往返,事实上就是俩条路过去(每一个点最多一次).所以想到流量为2,跑最大流.看是否满2,又要每 ...

  4. STL源代码剖析——STL算法之set集合算法

    前言 本节介绍set集合的相关算法,各自是并集set_union,差集set_difference,交集set_intersection 和对称差集set_symmetric_difference.这 ...

  5. js 变量、函数提升

    js 变量.函数提升 先简单理解下作用域的概念,方便对变量与函数提升的概念的理解 function foo() { var x = 1; if (x) { var x = 2; } console.l ...

  6. 【PA2013】【BZOJ3733】Iloczyn

    Description 给定正整数n和k,问是否能将n分解为k个不同正整数的乘积 Input 第一行一个数T(T<=4000)表示測试组数 接下来T行每行两个数n(n<=10^9),k(k ...

  7. String的属性和方法

    package com.zzu.java.array; public class TtString { /** * @author 程路超 * @param args */ public static ...

  8. YTU 2579: 填空题----删除指定字符

    2579: 填空题----删除指定字符 时间限制: 1 Sec  内存限制: 128 MB 提交: 164  解决: 61 题目描述 小明想要做个小程序,能够删除字符串中特定的字符. 例如:想要在下面 ...

  9. YTU 1006: Hero In Maze

    1006: Hero In Maze 时间限制: 1000 Sec  内存限制: 64 MB 提交: 72  解决: 22 题目描述 500年前,Jesse是我国最卓越的剑客.他英俊潇洒,而且机智过人 ...

  10. UltraEdit mac破解版

    2018-01-17 增加18.00.0.19破解 去官网下载原载,先运行一次,再在终端里执行下面代码就可以破解完成! printf '\x31\xC0\xFF\xC0\xC3\x90' | dd s ...