hdu 1469 Equations

Equations

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 5226    Accepted Submission(s): 2079

Problem Description

Consider equations having the following form:

a*x1^2+b*x2^2+c*x3^2+d*x4^2=0

a, b, c, d are integers from the interval [-50,50] and any of them cannot be 0.

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

Determine how many solutions satisfy the given equation.

Input

The input consists of several test cases. Each test case consists of a single line containing the 4 coefficients a, b, c, d, separated by one or more blanks.

End of file.

Output

For each test case, output a single line containing the number of the solutions.

Sample Input

1 2 3 -4
1 1 1 1

Sample Output

39088
0

哈希表基础题:

#include<stdio.h>
#include<algorithm>
#define M 2000004
int hash[M];
int main ()
{
	int a,b,c,d;
	int i,j;
	int sum,s[101];
	for(i=1;i<=100;i++)
		   s[i]=i*i;
	while(~scanf("%d%d%d%d",&a,&b,&c,&d))
	{
		if((a>0&&b>0&&c>0&&d>0)||(a<0&&b<0&&c<0&&d<0))
		{
			printf("0\n");
			continue;
		}
		sum=0;
		memset(hash,0,sizeof(hash));
		for(i=1;i<=100;i++)
			for(j=1;j<=100;j++)
				hash[a*s[i]+b*s[j]+M/2]++;  // M/2 是防止下标为负数。

			for(i=1;i<=100;i++)
				for(j=1;j<=100;j++)
				   sum+=hash[-(c*s[i]+d*s[j])+M/2];  // 亏大神们想得出啊!

				printf("%d\n",sum*16);
	}
	return 0;
}

hdu 1469 Equations

时间: 2024-10-16 11:27:15

hdu 1469 Equations的相关文章

HDU 1840 Equations (简单数学 + 水题)(Java版)

Equations 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1840 --每天在线,欢迎留言谈论. 题目大意: 给你一个一元二次方程组,a(X^2) + b(X) + c = 0 .求X解的个数. 思路: 分别讨论二次方程与一次方程的情况,再特殊处理下 a = b = c = 0 的情况. 感想: 是时候该水水题了. Java AC代码: 1 import java.math.*; 2 import java.util.Scanner; 3

hdu 1496 Equations

Equations 题意:给定一个四元二次方程的系数a,b,c,d;问有多少个解: a, b, c, d are integers from the interval [-50,50] and any of them cannot be 0. It is consider a solution a system ( x1,x2,x3,x4 ) that verifies the equation, xi is an integer from [-100,100] and xi != 0, any

hdu 1496 Equations (暴力+hash)

题目意思: http://acm.hdu.edu.cn/showproblem.php?pid=1496 对于方程a*x1^2+b*x2^2+c*x3^2+d*x4^2=0,给出a,b,c,d,求出有多少种方法使得方程成立,xi!=0,属于[-100,100] a,b,c,d也不为0,属于[-50,50]. Sample Input 1 2 3 -4 1 1 1 1 Sample Output 39088 0 题目分析: 直接暴力的话,会100^4,,超时,我们可以把等式转化为a*x1^2+b*

hdu 1496 Equations(暴力,哈希表 剪枝)

Equations Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 5630    Accepted Submission(s): 2237 Problem Description Consider equations having the following form: a*x1^2+b*x2^2+c*x3^2+d*x4^2=0 a,

半平面交模板 HDU 1469

题意就是要判断一个多边形是否存在核. 我们可以把沿着顺时针方向走这个多边形,对于每个边向量,我们取其右边的半平面,判断交是否为空即可. 对于半平面交算法,我只理解了O(n^2)的算法,大概就是用向量去切割多边形,对于O(nlogn)的算法,我从网上各种搜集以及参考了蓝书的实现,给出了一份能看的代码. O(n^2) 1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 #include<cmat

HDU - 1496 Equations (hash)

题意: 多组测试数据. 每组数据有一个方程 a*x1^2 + b*x2^2 + c*x3^2 + d*x4^2 = 0,方程中四个未知数 x1, x2, x3, x4 ∈ [-100, 100], 且都不为0. 给定a, b, c, d ∈ [-50, 50] ,且都不为0, 求上述条件下方程解的个数. 比赛的时候想到的是枚举三个,另一个可以直接算出来.但是一直TLE...结果就没做出来. 看了题解,用的hash,很巧妙.结果自己用map写还是T..最后用数组写的.     _φ(?_?? #i

HDU 4569 Special equations(数学推论)

题目 //想不出来,看了解题报告 /* 题意:给你一个最高幂为4的一元多项式,让你求出一个x使其结果模p*p为0. 题解:f(x)%(p*p)=0那么一定有f(x)%p=0,f(x)%p=0那么一定有f(x+p)%p=0. 所以我们可以开始从0到p枚举x,当f(x)%p=0,然后再从x到p*p枚举,不过每次都是+p,找到了输出即可,没有的话No solution! */ #include<stdio.h> int main() { int t,n; __int64 a[5],p; scanf(

HDU 4569 Special equations(取模)

Special equations Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 4569 Description Let f(x) = a nx n +...+ a 1x +a 0, in which a i (0 <= i <= n) are all known integers. We call f(x) 0 (mod

hdu - 2266 How Many Equations Can You Find (简单dfs)

http://acm.hdu.edu.cn/showproblem.php?pid=2266 给一个字符串和一个数n,在字符串中间可以插入+或者 -,问有多少种等于n的情况. 要注意任意两个数之间都可以插入也可以不插入,注意枚举完所有情况. #include <cstdio> #include <cstring> char s[15]; int n,l,cnt; void dfs(int k,int sum) { if(k==l) { if(sum==n) cnt++; retur