您的位置:首页 > 其它

[统计] hdu 4379 the more the better

2012-08-17 12:23 330 查看
/**
[统计] hdu 4379 the more the better
数据都2 * 10^7了却只给4s的时间是要说明hdu服务器比较强大啊,好吧,O(n)的算法。

解题报告 from 人人hdoj
简单题,首先想到所有小于 L/2 的,统统可以放进来,
最后,按照题意,还可能可以放一个大于 L/2 的数进来,
当小于 L/2 的数里面的最大值加上这个大于 L/2 的数的和小于 L 时,
答案加一。最后要注意所有数都小于 L/2 的处理。O(n) 算法可过此题。
*/
#include <stdio.h>
#include <algorithm>
using namespace std;

int main()
{
__int64 low,hig;
__int64 n,l,a,b,m,hh;
while(scanf("%I64d%I64d%I64d%I64d%I64d",&n,&l,&a,&b,&m) == 5)
{
low = 0;
hig = 10000000000LL;
int res = 0;
hh = l / 2;
while(n--)
{
b  = (b + a) % m;
if(b <= hh)
{
++res;
low = max(low,b);
}
else
{
hig = min(hig,b);
}
}
if(low + hig <= l)
++res;
printf("%d\n",res);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: