您的位置:首页 > 其它

POJ 1840 Eqs

2013-01-18 19:18 162 查看
Eqs

Time Limit: 5000MS Memory Limit: 65536K
Total Submissions: 9716 Accepted: 4760
Description
Consider equations having the following form:

a1x13+ a2x23+ a3x33+ a4x43+ a5x53=0

The coefficients are given integers from the interval [-50,50].

It is consider a solution a system (x1, x2, x3, x4, x5) that verifies the equation, xi∈[-50,50], xi != 0, any i∈{1,2,3,4,5}.

Determine how many solutions satisfy the given equation.

Input
The only line of input contains the 5 coefficients a1, a2, a3, a4, a5, separated by blanks.
Output
The output will contain on the first line the number of the solutions for the given equation.

Sample Input
37 29 41 43 47

Sample Output
654

Source
Romania OI 2002
做完这道题目的时候真是想跪了,看了别人的解题报告,在写代码,虽然思路一样但是迎接的确是无数次的wa,找数组的下标正着找就wa,如-1 为12500001   -2为12500002,而逆着找就ac ,如,-12500000是12500001 就能ac,现在也不知道是为什么,郁闷啊,难道是编译器的事情? 看到的解答一下吧。 我最后把数组分开写的正数用数组a表示,负数用数组b表示,这样过了,原来不过的原因怎么也找不到哎
不过的代码:s<0是,用注释掉的求s的代码就能过,用不进行的注释的就过不了,真是不懂得为什么啊?

#include <stdio.h>
#include <string.h>
#include <math.h>
short a[25000010];
int b[5];
int main()
{
int i,j,n,m,t,res,x,key;
long long int s;
for(i=0;i<=4;i++)
{
scanf("%d",&b[i]);
}
memset(a,0,sizeof(a));
for(i=-50;i<=50;i++)
{
if(i==0)
{
continue;
}
for(j=-50;j<=50;j++)
{
if(j==0)
{
continue;
}
s=(i*i*i*b[0]+j*j*j*b[1])*-1;
if(s<0)
{
s=-1*s+12500000;
//   s+=1+25000000;
}
a[s]+=1;
}
}
res=0; key=40;
for(i=-50;i<=50;i++)
{
if(i==0)
{
continue;
}
for(j=-50;j<=50;j++)
{
if(j==0)
{
continue;
}
for(x=-50;x<=50;x++)
{
if(x==0)
{
continue;
}
s=i*i*i*b[2]+j*j*j*b[3]+x*x*x*b[4];
if(s<0)
{
if(s<-12500000)
{
continue;
}
s=(-1*s)+12500000;
//   s+=1+25000000;
}
if(a[s])
{
res+=a[s];
}
}
}
}
printf("%d\n",res);
return 0;
}

 
数组分开写的过了
#include <stdio.h>
#include <string.h>
short a[12500003],b[12500003];
int c[6];
int main()
{
int i,j,n,m,t,res,x;
long long int s;
for(i=0;i<=4;i++)
{
scanf("%d",&c[i]);
}
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
for(i=-50;i<=50;i++)
{
if(i==0)
{
continue;
}
for(j=-50;j<=50;j++)
{
if(j==0)
{
continue;
}
s=(i*i*i*c[0]+j*j*j*c[1])*-1;
if(s<0)
{
s=s*-1;
b[s]+=1;
}else
{
a[s]+=1;
}
}
}
res=0;
for(i=-50;i<=50;i++)
{
if(!i)
{
continue;
}
for(j=-50;j<=50;j++)
{
if(!j)
{
continue;
}
for(x=-50;x<=50;x++)
{
if(!x)
{
continue;
}
s=i*i*i*c[2]+j*j*j*c[3]+x*x*x*c[4];
if(s<0)
{
s=-s;
if(s<=12500000&&b[s])
{
res+=b[s];
}
}else
{
if(s<=12500000&&b[s])
{
res+=b[s];
}
}
}
}
}
printf("%d\n",res);
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: