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
 
哈希只会一丢丢。就不写详解了。自己体会,O(∩_∩)O哈哈~
 
对于最后的结果要乘16,是因为,计算出来的结果可正可负,一共有 2^4 种情况
 
using namespace std;
const int maxn = 2000005;
const int h = 1000000;
int hash1[maxn];
int a, b, c, d, sum, k; //主思路: 分两段计算 最后乘16( 2^4 )
int main()
{
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 )
{
cout << "0" << endl ;
continue ;
}
memset(hash1,0,sizeof(hash1));
sum = 0 ;
for(int i=1; i<=100; i++)
for(int j=1; j<=100; j++)
hash1[ a * i * i + b * j * j + h ] ++ ;
for(int i=1; i<=100; i++)
for(int j=1; j<=100; j++)
sum += hash1[ h - c * i * i - d * j * j ] ;
cout << sum*16 << endl ;
} return 0;
}

ACM题目————Equations的更多相关文章

  1. ACM题目————中缀表达式转后缀

    题目描述 我们熟悉的表达式如a+b.a+b*(c+d)等都属于中缀表达式.中缀表达式就是(对于双目运算符来说)操作符在两个操作数中间:num1 operand num2.同理,后缀表达式就是操作符在两 ...

  2. HDU ACM 题目分类

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

  3. ACM题目推荐(刘汝佳书上出现的一些题目)[非原创]

    原地址:http://blog.csdn.net/hncqp/article/details/1758337 推荐一些题目,希望对参与ICPC竞赛的同学有所帮助. POJ上一些题目在http://16 ...

  4. 有一种acm题目叫做,奇葩!

    本文全然没有技术含量,纯粹是娱乐. 我事实上想写点东西.可是近期好像做计算几何做得太多了,一种想说说不出东西的感觉,唯有写一下一些奇葩的题目了. HDU3337:Guess the number pi ...

  5. ACM题目————STL练习之求次数

    题目地址:http://acm.nyist.net/JudgeOnline/problem.php?pid=1112 描述 题意很简单,给一个数n 以及一个字符串str,区间[i,i+n-1] 为一个 ...

  6. ACM题目————zoj问题

    题目1006:ZOJ问题 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:20322 解决:3560 题目描述: 对给定的字符串(只包含'z','o','j'三种字符),判断他是否能AC. ...

  7. ACM题目————又见拦截导弹

    描述 大家对拦截导弹那个题目应该比较熟悉了,我再叙述一下题意:某国为了防御敌国的导弹袭击,新研制出来一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:它的第一发炮弹能够到达任意的高度,但是以后每一发炮 ...

  8. ACM题目————还是畅通工程

    Submit Status Description 某省调查乡村交通状况,得到的统计表中列出了任意两村庄间的距离.省政府“畅通工程”的目标是使全省任何两个村庄间都可以实现公路交通(但不一定有直接的公路 ...

  9. ACM题目————小A的计算器

    Description 以往的操作系统内部的数据表示都是二进制方式,小A新写了一个操作系统,系统内部的数据表示为26进制,其中0-25分别由a-z表示.  现在小A要在这个操作系统上实现一个计算器,这 ...

随机推荐

  1. The Havel-Hakimi Algorithm

    1.If any di>=n then fail 2.If there is an odd number of odd degrees then fail 3.If there is a di& ...

  2. 转:python字符串/元组/列表/字典互转

    #-*-coding:utf-8-*-  #1.字典 dict = {'name': 'Zara', 'age': 7, 'class': 'First'} #字典转为字符串,返回:<type ...

  3. TPageControl组件

    TPageControl的功能是创建多个Dialog页,而这些重叠的每一个页Dialog就是通过TTabSheet对象实现的

  4. WOW: 宏

    1.常用的宏命令 1.1常用的宏命令 1.释放技能命令 /cast 释放一个或多个技能,可以加入一些条件判断,是最常用的命令 /castsequence 依次释放释放数个技能,同样可以加入一些条件判断 ...

  5. &nbsp|&quot|&amp|&lt|&gt等html字符转义

    提示:请直接按CTRL+F搜索您要查找的转义字符.    原文地址:http://write.blog.csdn.net/postedit/8817826 常用表: No. 文字表記 10進表記 16 ...

  6. 如何为 Eclipse 中的 Java 源文件设置为 UTF-8 默认编码(转)

    要让一个 Java 源文件打开时编码格式为 UTF-8,需要做2件事情: 1)设置Java 源文件的默认编码格式为UTF-8: 2)设置workspace的编码格式为UTF-8. 相应设置如下: 设置 ...

  7. php js表单登陆验证

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  8. AS-demo09

    ,mainifast: <uses-permission android:name="android.permission.SET_WALLPAPER"/> , < ...

  9. 杭电oj 1016 Prime Ring Problem

    Prime Ring Problem Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  10. oracle的用户

    1:创建用户 create user zhaoyb identified by zhaoyb default tablespace HUAPUSALEDB create user 用户名 identi ...