hdu 4379 The More The Better
2012-08-17 14:56
288 查看
题目描述:
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. (1 ≤ n ≤ 2*107,
1 ≤ L ≤ 2*109, 1 ≤ A, B, mod ≤ 109)
题解:
题目可以用反证法证明,加入集合中的数大于l/2的数至多有1个,所以这个题做法如下:
对于所有小于等于L/2 的,统统可以放进来,并设放入的那些的最大值为maxn。然后对于没有放入的数,看看是否有一个数x,满足x+maxn<=l,如果有的话,答案加1.
这个题需要注意的是,竟然卡常数!!long long过不了,int又会溢出。所以我们不妨回过来看看这个式子Xk =
(A * k + B) % mod,可以推出xk=(x(k-1)+a)%mod,这样就用加法来求并取模就不会超过unsigned int。
AC代码1903ms才过
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. (1 ≤ n ≤ 2*107,
1 ≤ L ≤ 2*109, 1 ≤ A, B, mod ≤ 109)
题解:
题目可以用反证法证明,加入集合中的数大于l/2的数至多有1个,所以这个题做法如下:
对于所有小于等于L/2 的,统统可以放进来,并设放入的那些的最大值为maxn。然后对于没有放入的数,看看是否有一个数x,满足x+maxn<=l,如果有的话,答案加1.
这个题需要注意的是,竟然卡常数!!long long过不了,int又会溢出。所以我们不妨回过来看看这个式子Xk =
(A * k + B) % mod,可以推出xk=(x(k-1)+a)%mod,这样就用加法来求并取模就不会超过unsigned int。
AC代码1903ms才过
#include<iostream> #include<cstdio> #include<cstring> using namespace std; unsigned int a,b,k,n,l,last; unsigned int mod; bool v[21000000]; int main() { while(cin>>n>>l>>a>>b>>mod) { for(unsigned int i=1;i<=n;i++) v[i]=false; unsigned int ans=0;unsigned int max=0,t; last=b; for(unsigned int i=1;i<=n;i++) { t=(last+a)%mod; if(t*2<=l) { ans++;v[i]=true; if(t>max)max=t; } last=t; } last=b; for(unsigned int i=1;i<=n;i++) { t=(last+a)%mod; if((!v[i])&&t+max<=l){ans++;break;} last=t; } cout<<ans<<endl; } return 0; }
相关文章推荐
- BNU OJ The More The Better || HDU 4379
- HDU 4379 - The More The Better
- hdu——4379 ——The More The Better
- HDU:4379 The More The Better
- hdu 4379 The More The Better ( 2012 Multi-University Training Contest 8)
- [统计] hdu 4379 the more the better
- hdu 4379 The More The Better 多校联合赛事第8场
- HDU_4379_The More The Better
- HDU 4379 The More The Better
- HDU 4379 The More The Better [坑爹想法题]
- HDU 4379 The More The Better [坑爹想法题]
- HDU 4379 The More The Better [枚举]
- hdu 1561 the more the better (树形DP)
- 【优化】HDU1856——The More The Better(顺便求解犇们JAVA版为啥不过)
- hdoj(hdu)-1561-the more the better
- More Is Always Better: The Power Of Simple Ensembles
- hdu1856——More is better
- hdu 1856 More is better
- hdu 1856 More is better
- hdu--1856--More is better