Equations

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

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
 
Source
 
题意:
计算a*x1^2+b*x2^2+c*x3^2+d*x4^2=0有多少解。系数取值[-50,50],不取0,x取值[-100,100],不取0.
代码:
//判断一下当系数的符号都相同时显然无解。可以把四重循环分成两个二重循环,ax1^2+bx2^2=-cx3^2-dx4^2
//只要两边有相同的值时就出现一个解,由于是x^2,每个x对应正负两个解,4个x共有16个解。
//最重要的是hash.
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int a,b,c,d;
int m[];
int main()
{
while(~scanf("%d%d%d%d",&a,&b,&c,&d)){
if((a>&&b>&&c>&&d>)||(a<&&b<&&c<&&d<)){
printf("0\n");
continue;
}
memset(m,,sizeof(m));
for(int i=;i<=;i++){
for(int j=;j<=;j++){
m[a*i*i+b*j*j+]++;
}
}
int ans=;
for(int i=;i<=;i++){
for(int j=;j<=;j++){
ans+=m[-c*i*i-d*j*j+];
}
}
printf("%d\n",ans*);
}
return ;
}

HDU1496 hash的更多相关文章

  1. 折半枚举+Hash(HDU1496升级版)

    题目链接:N - 方程的解 给定一个四元二次方程: Ax1^2+Bx2^2+Cx3^2+Dx4^2=0 试求−1000≤x1,x2,x3,x4≤1000非零整数解的个数. −10000≤A,B,C,D ...

  2. HDU1496(巧妙hash)

    Equations Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  3. 复杂的 Hash 函数组合有意义吗?

    很久以前看到一篇文章,讲某个大网站储存用户口令时,会经过十分复杂的处理.怎么个复杂记不得了,大概就是先 Hash,结果加上一些特殊字符再 Hash,结果再加上些字符.再倒序.再怎么怎么的.再 Hash ...

  4. 对抗密码破解 —— Web 前端慢 Hash

    (更新:https://www.cnblogs.com/index-html/p/frontend_kdf.html ) 0x00 前言 天下武功,唯快不破.但在密码学中则不同.算法越快,越容易破. ...

  5. 散列表(hash table)——算法导论(13)

    1. 引言 许多应用都需要动态集合结构,它至少需要支持Insert,search和delete字典操作.散列表(hash table)是实现字典操作的一种有效的数据结构. 2. 直接寻址表 在介绍散列 ...

  6. hash表长度优化证明

    hash表冲突的解决方法一般有两个方向: 一个是倾向于空间换时间,使用向量加链表可以最大程度的在节省空间的前提下解决冲突. 另外一个倾向于时间换空间,下面是关于这种思路的一种合适表长度的证明过程: 这 ...

  7. SQL Server-聚焦查询计划Stream Aggregate VS Hash Match Aggregate(二十)

    前言 之前系列中在查询计划中一直出现Stream Aggregate,当时也只是做了基本了解,对于查询计划中出现的操作,我们都需要去详细研究下,只有这样才能对查询计划执行的每一步操作都了如指掌,所以才 ...

  8. C# salt+hash 加密

    一.先明确几个基本概念 1.伪随机数:pseudo-random number generators ,简称为:PRNGs,是计算机利用一定的算法来产生的.伪随机数并不是假随机 数,这里的" ...

  9. SQL 提示介绍 hash/merge/concat union

    查询提示一直是个很有争议的东西,因为他影响了sql server 自己选择执行计划.很多人在问是否应该使用查询提示的时候一般会被告知慎用或不要使用...但是个人认为善用提示在不修改语句的条件下,是常用 ...

随机推荐

  1. Oracle中注意用户的访问权限

    新增表.序列.存储过程等,要注意用户(例如System)的权限.如果在增删改查过程中出现数据库读写权限的报错,则在建表(或者序列.存储过程等)时,在脚本前面加 GRANT CREATE TABLE T ...

  2. MyEclipse的真正价值——时间等于金钱

    全世界成千上万的Java开发者选择MyEclipse作为首选的Eclipse IDE,甚至超过了著名的开发工具 IBM Rational和Eclipse Java. 为什么? 很简单,MyEclips ...

  3. ComponentName意思

    ComponentNameActivity Intent i=new Intent(); i.setComponent(new ComponentName(String packageName,Str ...

  4. SQL远程备份

    原文:SQL远程备份 set ANSI_NULLS ON set QUOTED_IDENTIFIER ON go   -- ====================================== ...

  5. 使用response实现文件下载功能

    response.setContentType("text/html;charset=utf-8");  response.setCharacterEncoding("u ...

  6. SpecFlow使用入门之C# BDD

    SpecFlow使用入门 http://www.specflow.org/ SpecFlow是一个BDD工具,在这里对BDD不多赘述,你可以阅读一下微软2010年十二月的一篇文章,此外如果你想要更多了 ...

  7. JavaScript 动画库和开发框架

    1. Tween JS TweenJS 是一个简单的 JavaScript 补间动画库.能够很好的和 EaselJS 库集成,但也不依赖或特定于它.它支持渐变的数字对象属性和 CSS 样式属性.API ...

  8. 深入剖析Provider Model

    Membership三步曲之进阶篇 - 深入剖析Provider Model Membership 三步曲之进阶篇 - 深入剖析Provider Model 本文的目标是让每一个人都知道Provide ...

  9. C# 学习笔记2 C#底层的一些命令运行

    C#在DCP中运行的方法: 1.转到相应的目录 cd d:\1 2.输入csc /target:exe 2.cs 或者 csc /t:exe 2.cs 或者 csc 2.cs 在里边引用外部程序集的方 ...

  10. Apache指南:CGI动态页面

    概要 相关模块 相关指令 mod_alias mod_cgi AddHandler Options ScriptAlias CGI(公共网关接口[Common Gateway Interface])定 ...