POJ

来源:互联网 发布:熟悉掌握办公软件 编辑:程序博客网 时间:2024/05/29 10:57

传送门

Eqs
Time Limit: 5000MS Memory Limit: 65536KTotal Submissions: 16694 Accepted: 8193

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


题意:问你满足a1x1^3+ a2x2^3+ a3x3^3+ a4x4^3+ a5x5^3=0条件的有多少组。

先枚举两层for找到一些组。 等于把方程转换成 a1x1^3+ a2x2^3=-(a3x3^3+ a4x4^3+ a5x5^3)

具体看代码就好,char用的内存比int小,所以用char 

//china no.1#pragma comment(linker, "/STACK:1024000000,1024000000")#include <vector>#include <iostream>#include <string>#include <map>#include <stack>#include <cstring>#include <queue>#include <list>#include <stdio.h>#include <set>#include <algorithm>#include <cstdlib>#include <cmath>#include <iomanip>#include <cctype>#include <sstream>#include <functional>#include <stdlib.h>#include <time.h>#include <bitset>using namespace std;#define pi acos(-1)#define endl '\n'#define srand() srand(time(0));#define me(x,y) memset(x,y,sizeof(x));#define foreach(it,a) for(__typeof((a).begin()) it=(a).begin();it!=(a).end();it++)#define close() ios::sync_with_stdio(0); cin.tie(0);#define FOR(x,n,i) for(int i=x;i<=n;i++)#define FOr(x,n,i) for(int i=x;i<n;i++)#define W while#define sgn(x) ((x) < 0 ? -1 : (x) > 0)#define bug printf("***********\n");typedef long long LL;const int INF=0x3f3f3f3f;const LL LINF=0x3f3f3f3f3f3f3f3fLL;const int dx[]={-1,0,1,0,1,-1,-1,1};const int dy[]={0,1,0,-1,-1,1,-1,1};const int maxn=25000000;const int maxx=1e7+100;const double EPS=1e-7;const int MOD=10000007;#define mod(x) ((x)%MOD);template<class T>inline T min(T a,T b,T c) { return min(min(a,b),c);}template<class T>inline T max(T a,T b,T c) { return max(max(a,b),c);}template<class T>inline T min(T a,T b,T c,T d) { return min(min(a,b),min(c,d));}template<class T>inline T max(T a,T b,T c,T d) { return max(max(a,b),max(c,d));}inline int Scan(){    int Res=0,ch,Flag=0;    if((ch=getchar())=='-')Flag=1;    else if(ch>='0' && ch<='9')Res=ch-'0';    while((ch=getchar())>='0'&&ch<='9')Res=Res*10+ch-'0';    return Flag ? -Res : Res;}//freopen( "in.txt" , "r" , stdin );//freopen( "data.out" , "w" , stdout );//cerr << "run time is " << clock() << endl;char hash[maxn+2];int a1,a2,a3,a4,a5;int main(){    while(scanf("%d%d%d%d%d",&a1,&a2,&a3,&a4,&a5)!=EOF)    {        me(hash,0);        int cnt=0,t=25000000;        for(int i=-50;i<=50;i++)            for(int j=-50;j<=50;j++)        {            if(!(i*j)) continue;            int temp=a1*i*i*i+a2*j*j*j;            hash[temp+maxn/2]++;        }        for(int i=-50;i<=50;i++)            for(int j=-50;j<=50;j++)               for(int k=-50;k<=50;k++)        {            if(!(i*j*k)) continue;            int temp=a3*i*i*i+a4*j*j*j+a5*k*k*k;            if(temp>=-maxn/2&&temp<=maxn/2)                cnt+=hash[-temp+maxn/2];        }        cout<<cnt<<endl;    }}


原创粉丝点击