The More The Better
Time Limit: 4000/2000 MS (Java/Others)Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1474Accepted Submission(s): 368
Problem Description
Given an sequence of numbers {X1, X2, ... , Xn}, where Xk = (A * k + B) % mod. Your task is to find the maximum sub sequence {Y1, Y2, ... , Ym} where every
pair of (Yi, Yj) satisfies Yi + Yj <= L (1 ≤ i < j ≤ m),
and every Yi <= L (1 ≤ i ≤ m ).
Now given n, L, A, B and mod, your task is to figure out the maximum m described above.
Input
Multiple test cases, process to the end of input. Every test case has a single line. A line of 5 integers: n, L, A, B and mod. (1 ≤ n ≤ 2*107, 1 ≤ L ≤ 2*109, 1 ≤ A, B, mod ≤ 109)
Output
For each case, output m in one line.
Sample Input
Sample Output
/*题意是 给出A,B,mod n l
问对于k 从1到n 按公式 Xk = (A * k + B) % mod 求出的串中
找出子串Y1, Y2, ... , Ym 且对于串中任意元素小于l 且任意2元素之和小于l
问 找出的串中 最多有多少个元素 即m的值
*/
/*由题意 Yi + Yj <= L 任意2个元素之和小于l 那么最多只可能有1个元素大于l
那么 把所有的小于l/2的都入选 那么这些数肯定是满足题目要求的
那么现在还可以加入一个大于l/2的 前提是 入选的中最大的那个 加上这个数小于l
那么只要入选的当中的最大的加上没有入选的中的最小的 如果这2者之和小于l 那么又可以入选一个
*/
/*一开始做的误区 : 把串当成了连续的子串 子串本是可以不连续的*/
#include<stdio.h>
int main()
{
__int64 i,n,l,a,b,mod,ban,num,max,min,x;//max是入选的最大值 min是未入选的最小值
while(scanf("%I64d %I64d %I64d %I64d %I64d",&n,&l,&a,&b,&mod)!=EOF)
{
ban=l/2;num=0;max=-1;min=9999999999999;
for(i=1;i<=n;i++)
{
x=((__int64)((__int64)a*i+b)%mod);
if(x<=ban)// 小于等于l/2 则入选
{
num++;
if(max<x) max=x;
}
else
{
if(min>x) min=x;
}
}
if(max+min<=l) num++;
printf("%I64d\n",num);
}
return 0;
}
相关推荐
2017hdu多校联合训练第一场标程及数据
HDU2013暑期多校联合训练第一场0723-解题报告和标程
ACM/ICPC 2010年多校联合第十场第九题的解题报告及代码,AC代码有三个,最好的是src
2019 Multi-University Training Contest 4(2019hdu多校第五场数据与标程),欢迎大家下载
此乃2012多校联赛第五场的题目+数据+题解+标程
2014 Multi-University Training Contest 1多校联合赛标程和部分数据。
2019 Multi-University Training Contest 4(2019hdu多校第六场数据与标程)
有2019 Multi-University Training Contest 4,hdu多校第四场的题解,数据标程,有需要的可以下载哦
13年3月30日多校第二场解题报告+标程
有2019 Multi-University Training Contest 9,hdu多校第9场的题解,数据标程,有需要的可以下载哦
这份压缩爆内包含了2019年杭电多校第二场的数据与标程,欢迎下载
杭电ACMhdu1163
HDU2000至2099题的题目以及AC代码(含思路) 适合刚刚接触ACM的同学哦~ emmmm凑字
hdu1001解题报告
hdu 1574 passed sorce
HDU1059的代码
HDU的1250,主要是利用高精度加法,但是代码有点繁琐,效率不是很高
HDU的一题........HDU DP动态规
hdu2101AC代码
The least common multiple (LCM) of a set of positive integers is the smallest positive integer which is divisible by all the numbers in the set. For example, the LCM of 5, 7 and 15 is 105. Input Input...