POJ - 1840 hash去重
2017-08-02 13:54
183 查看
传送门
Eqs
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
Sample Output
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;
}
}
Eqs
Time Limit: 5000MS | Memory Limit: 65536K | |
Total Submissions: 16694 | Accepted: 8193 |
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;
}
}
相关文章推荐
- POJ-1840 Eqs Hash
- POJ 1840 HASH
- POJ 1840 Eqs (Hash)
- POJ 1840 Hash 效率就是高~ 空间就是费
- POJ 1840 HASH
- POJ 1840 Eqs 二分+map/hash
- POJ 1840 Eqs(hash)
- POJ 1840 Eqs (hash)
- POJ 1840 Eqs(枚举+HASH)
- POJ 1840 Eqs hash
- POJ 1840 (hash)
- POJ - 1840 hash去重
- POJ 1840 Eqs (大整数的Hash)
- POJ - 1840 hash去重
- HDU-1496-Equations && POJ-1840-Eqs (hash)
- POJ 1840 - Hash
- POJ - 1840 hash去重
- poj 1840 Eqs(暴力枚举+hash)
- POJ - 1840 hash去重
- [POJ 1840]Eqs[hash][枚举]