Equations

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3978    Accepted Submission(s): 1602

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
 
Author
LL
 
Recommend
LL
 
解题思路:暴力+hash,主要是想练练hash,一直认为hash是高端黑,用线性探测再散列处理冲突,记得不知道谁说过处理余数的数一般用上素数,不要忘了最后乘上16,因为四个数有可能是正负
 #include<stdio.h>
#include<string.h>
#define MAXN 50001
int num[MAXN], store[MAXN]; int hash(int cur)
{
int temp = cur%MAXN;
if(temp < ) temp += MAXN;
while(num[temp] != && store[temp] != cur)
{
temp = (temp+)%MAXN;
}
return temp;
} int main()
{
// freopen("input.txt", "r", stdin);
int rate[], a, b, c, d, i, j, sum, temp, res;
for(i=; i<; ++i) rate[i] = i*i;
while(scanf("%d%d%d%d", &a, &b, &c, &d) != EOF)
{
if((a>&&b>&&c>&&d>) || (a<&&b<&&c<&&d<))
{
printf("0\n");
continue;
}
memset(num, , sizeof(num));
for(i=; i<; ++i)
for(j=; j<; ++j)
{
temp = a*rate[i]+b*rate[j];
res = hash(temp);
store[res] = temp;
num[res]++;
} sum = ; for(i=; i<; ++i)
for(j=; j<; ++j)
{
temp = -(c*rate[i]+d*rate[j]);
res = hash(temp);
sum += num[res];
} printf("%d\n", sum****);
}
return ;
}

HDU ACM 1496 Equations的更多相关文章

  1. hdu 1496 Equations

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1496 Equations Description Consider equations having ...

  2. hdu 1496 Equations hash表

    hdu 1496 Equations hash表 题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1496 思路: hash表,将原来\(n^{4}\)降 ...

  3. hdu acm 1028 数字拆分Ignatius and the Princess III

    Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K ...

  4. HDU 1496 Equations(哈希表)

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=1496 [题目大意] 给出一个方程ax1^2+bx2^2+cx3^2+dx4^2=0,求-100到1 ...

  5. HDU 1496 Equations hash HDU上排名第一!

    看题传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1496 题目大意: 给定a,b,c,d.a*x1^2+b*x2^2+c*x3^2+d*x4^2=0 ...

  6. HDU 1496 Equations 等式(二分+暴力,技巧)

    题意:给出4个数字a,b,c,d,求出满足算式a*x1^2+b*x2^2+c*x3^2+d*x4^2=0的 (x1,x2,x3,x4) 的组合数.x的范围[-100,100],四个数字的范围 [-50 ...

  7. HDU - 1496 Equations (hash)

    题意: 多组测试数据. 每组数据有一个方程 a*x1^2 + b*x2^2 + c*x3^2 + d*x4^2 = 0,方程中四个未知数 x1, x2, x3, x4 ∈ [-100, 100], 且 ...

  8. HDU ACM 题目分类

    模拟题, 枚举1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 104 ...

  9. HDU 4569 Special equations(取模)

    Special equations Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

随机推荐

  1. 使用 Async 和 Await 的异步编程

    来自:http://msdn.microsoft.com/library/vstudio/hh191443   异步对可能起阻止作用的活动(例如,应用程序访问 Web 时)至关重要. 对 Web 资源 ...

  2. NDK(19)简单示例:ndk调用java基本方法、数组;使用stl、访问设备

    一.ndk调用java类示例 1,调用基本方法 /* * Class: com_example_ndksample_MainActivity * Method: ndkFindJavaClass * ...

  3. 加密解密(10)常见HASH算法:MD5(128bit),SHA1(160bit)

  4. OPENGL画图类库

    链接  https://www.opengl.org/wiki/Language_bindings http://blog.csdn.net/luozhuang/article/details/421 ...

  5. Oracle SQL大全

    一. 基本操作表和数据 -- 建表 CREATE TABLE ab_student ( id number(4) ) create table ab_class( id number(4), name ...

  6. 函数buf_LRU_old_adjust_len

    调整LUR_old位置,放到八分之五位置,是新的,后八分之三是旧的 512个页全变成新的,然后从后往前数,数到8分之3,设置为旧的 /********************************* ...

  7. bzoj2251

    以前看到这道题想到的是SA,做起来不是很美观 学了SAM之后,这题简直是随便搞 ..,'] of longint; s,sa,mx,w,fa:..] of longint; i,n,last,t:lo ...

  8. UVa 10735 (混合图的欧拉回路) Euler Circuit

    题意: 给出一个图,有的边是有向边,有的是无向边.试找出一条欧拉回路. 分析: 按照往常的思维,遇到混合图,我们一般会把无向边拆成两条方向相反的有向边. 但是在这里却行不通了,因为拆成两条有向边的话, ...

  9. UVa 10305 (拓扑排序) Ordering Tasks

    题意: 经典的拓扑排序.有n个任务,然后某些任务必须安排在某些任务前面完成,输出一种满足要求的序列. 分析: 拓扑排序用离散里面的话来说就是将偏序关系拓展为全序关系.我们将“小于”这种关系看做一条有向 ...

  10. CSS强制英文换行

    1. word-break:break-all;只对英文起作用,以字母作为换行依据 2. word-wrap:break-word; 只对英文起作用,以单词作为换行依据 3. white-space: ...