hdu 4379 The More The Better
来源:互联网 发布:成考和网络教育区别 编辑:程序博客网 时间:2024/06/05 01:50
题目描述:
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;}
- 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 4379The More The Better
- hdu-The more, The Better
- hdu The more, The Better
- hdu The more, The Better
- The more, The Better HDU
- The more, The Better HDU
- hdu——4379 ——The More The Better
- BNU OJ The More The Better || HDU 4379
- HDU 4379 The More The Better [坑爹想法题]
- hdoj(hdu)-1561-the more the better
- hdu 1561 The more,The better
- HDU 1516 The more, The Better
- hdu 1561 the more,the better
- Android从驱动层到应用程序层的通信
- 全球地名中英文对照表(A)
- 细说 Form (表单)
- HDU1241 DFS
- sql保留n位个小数位
- hdu 4379 The More The Better
- ASP.NET 高级编程基础第一篇—基础介绍
- java多线程总结
- 类与类之间的关系图(Class Diagram,UML图)
- Android适配器之-----SimpleAdapter
- 感谢eygle帮我找到密码——能沾上eygle光就是不错:)
- GreenCam:自动关闭显示器的节能好帮手
- 全球地名中英文对照表(B)
- shell脚本语法--case/exac