您的位置:首页 > 其它

FOJ 1404 Andy 的作业

2009-08-12 10:16 405 查看
http://acm.fzu.edu.cn/problem.php?pid=1404

解题思路:大数相乘,不过我的程序放在FOJ上运行时,拆成6位或13位为一个元素值才能过,拆成其他位,就过不了,不明原因,深感郁闷中,纠结了我一个晚上。以后把原因找出来了再次更新吧。

#include <stdio.h>
#include <string.h>
#define LL  unsigned long long
#define Max 10000000000000

LL res[63];
int i,j;
int M,N;
long value[801];

void mul(int L,int R)
{
int len=1;
long up;
memset(res,0,sizeof(res));
res[0] = 1;
for(i=L;i<=R;i++)
if(value[i]==0)
{
printf("0/n");
return ;
}
for (i=L;i<=R;i++)
{
up=0;
for (j=0;j<len;j++)
{
res[j] = res[j]*value[i]+up;
up = res[j]/Max;
res[j] = res[j]%Max;
}
if (up>0)
res[len++] = up;
}
printf("%llu",res[len-1]);
for (i=len-2;i>=0;i--)
printf("%13.13llu",res[i]);
printf("/n");
}

int main()
{
int L,R;
while (scanf("%d%d",&M,&N)!=EOF)
{
for(i=1;i<=M;i++)
scanf("%ld",&value[i]);
while (N--)
{
scanf("%d%d",&L,&R);
mul(L,R);
}
printf("Homework Finished/n");
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: