POJ 1840 Eqs

Eqs
Time Limit: 5000MS Memory Limit: 65536K
Total Submissions: 9716 Accepted: 4760

Description

Consider equations having the following form:
a1x1 3+ a2x2 3+ a3x3 3+ a4x4 3+ a5x5 3=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

做完这道题目的时候真是想跪了,看了别人的解题报告,在写代码,虽然思路一样但是迎接的确是无数次的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;
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值