与杭电1496类似,都是通过hash+枚举做的。

CODE:

#include <stdlib.h> 
#include <stdio.h>
#include <string.h>
using namespace std; 
  
const int SIZE = 25000000
char hash[SIZE+1]; 
const int N = SIZE/2;
int p[100];

int calCube(int x)
{
    return x*x*x;
}

int main() 
{
    int a1, a2, a3, a4, a5;
    while(~scanf("%d%d%d%d%d", &a1, &a2, &a3, &a4, &a5))
    {
        int tot = 0;
        memset(hash, 0sizeof(hash));
        for(int i = -50; i <= 50; i++)
            for(int j = -50; j <= 50; j++)
            {
                if(i != 0 && j != 0)
                {
                    int temp = -(a1*calCube(i)+a2*calCube(j));
                    hash[N+temp]++;
                }
            }
        for(int i = -50; i <= 50; i++)
        for(int j = -50; j <= 50; j++)
            for(int k = -50; k <= 50; k++)
            {
                if(i != 0 && j != 0 && k != 0)
                {
                    int temp = a3*calCube(i)+a4*calCube(j)+a5*calCube(k);
                    if(temp <= N && temp >= -N)
                        tot += hash[N+temp];
                }
            }
        printf("%d\n", tot);
    } 

 

posted on 2012-08-30 12:10  有间博客  阅读(184)  评论(0编辑  收藏  举报