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. 获取当前时间 YYYY-MM-DD

    1.函数封装 /** * 获取当前时间 * 格式YYYY-MM-DD */ Vue.prototype.getNowFormatDate = function() { var date = new D ...

  2. 初识mina框架

    step1:创建java工程,导入jar包 step2:在src下配置log4j.properties文件 log4j.rootLogger=DEBUG,MINA,file log4j.appende ...

  3. PHP开发者实用的代码

    一.查看邮件是否已被阅读 当你在发送邮件时,你或许很想知道该邮件是否被对方已阅读.这里有段非常有趣的代码片段能够显示对方IP地址记录阅读的实际日期和时间. <? error_reporting( ...

  4. 深度学习笔记之关于总结、展望、参考文献和Deep Learning学习资源(五)

    不多说,直接上干货! 十.总结与展望 1)Deep learning总结 深度学习是关于自动学习要建模的数据的潜在(隐含)分布的多层(复杂)表达的算法.换句话来说,深度学习算法自动的提取分类需要的低层 ...

  5. poj1840Eqs(哈希判重)

    题目链接: 传送门 思路: 这道题是一个简单的hash的应用,假设直接暴力的话肯定承受不了5重for循环,所以比赛的时候我先到分成两组.可是后来用到了很多数组,然后想到数字太大,还先到stl判重, 后 ...

  6. Flex+Java+Blazeds

    1.环境:jdk1.6,Flex4.6 2.工具:MyEclipse10 3.server:Tomcat7 4.连接方式:Blazeds 5.项目类型:Flex项目 6.步骤 (1)新建Flex项目一 ...

  7. diy数据库(二)--网络通信类

    一.首先,我们先实现OSS层的ossSocket类.供数据库client和数据库引擎进行通信 友情提示:相应上面的类图的头文件和源码附在了本文的最以下. int _fd ;//socket的文件描写叙 ...

  8. android锁屏软件制作

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/mingyue_1128/article/details/33726515 转载请标明出处http:/ ...

  9. ABAP 读取FTP文件

    VALUE '172.168.1.250'. VALUE 'username'. VALUE 'password'. ."密钥 CONSTANTS: cns_rfcdest LIKE rfc ...

  10. CentOS 6.6实现永久修改DNS地址的方法

    本文实例讲述了CentOS 6.6实现永久修改DNS地址的方法. 百牛信息技术bainiu.ltd整理发布于博客园 分享给大家供大家参考,具体如下:1.配置ip地址文件 /etc/sysconfig/ ...