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. vux tabbar 组件

    1.App.vue <!-- 入口文件 --> <template> <div id="app"> <!-- 视图层 --> < ...

  2. AngularJS自己定义标签加入回调函数eval()

    function helloworld(name){ console.log("hello!!!!!"+name) } var name="zhangsan"; ...

  3. MySQL InnoDB类型数据库的恢复

     MySQL的数据库文件直接复制便可以使用,但是那是指“MyISAM”类型的表. 而使用MySQL-Front直接创建表,默认是“InnoDB”类型,这种类型的一个表在磁盘上只对应一个“*.frm”文 ...

  4. 高清接口芯片---gv7600、sii9135

    http://www.travellinux.com/download/海思Hi3516%20demo单板使用指南.pdf gv7600 sdi 串行数字接口 parrlar 并行数字接口 http: ...

  5. Struts2逻辑视图与视图资源

  6. vsftp 777权限

    1. setsebool -P ftpd_disable_trans 1 2. service vsftpd restart

  7. 数据库sqlite3的使用-ios中引用方法

    一.简单说明 在iOS中使用SQLite3,首先要添加库文件libsqlite3.dylib和导入主头文件. 导入头文件,可以使用库中的函数(是纯C语言的) 二.具体说明 新建一个项目,在项目的主界面 ...

  8. JavaScript Array 的学习

    首先创建数组 var empty = [];//创建一个空的数组: var diffType = [1,'a',2.3,{},[4,5],,];//创建一个包含不同类型的数组 var undef = ...

  9. BZOJ_4199_[Noi2015]品酒大会_后缀自动机

    BZOJ_4199_[Noi2015]品酒大会_后缀自动机 Description 一年一度的“幻影阁夏日品酒大会”隆重开幕了.大会包含品尝和趣味挑战两个环节,分别向优胜者颁发“首席品 酒家”和“首席 ...

  10. gcc编译系统

    一. C语言编译过程 C语言的编译过程可分为四个阶段: 1.预处理(Preprocessing) 对源程序中的伪指令(即以#开头的指令)和特殊符号进行处理的过程. 伪指令包括:1)宏定义指令: 2)条 ...