【题目链接】 http://acm.hdu.edu.cn/showproblem.php?pid=1496

【题目大意】

  给出一个方程ax1^2+bx2^2+cx3^2+dx4^2=0,求-100到100范围内的解集数量

【题解】

  将ax1^2+bx2^2存入哈希,反查-cx3^2-dx4^2.

【代码】

#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
const int mod=1<<15;
int n,a,b,c,d,x[200],head[mod],cnt;
struct data{int x,nxt,s;}g[mod];
long long ans;
inline int Hash(int x){return (x+mod)&(mod-1);}
void insert(int x){
int key=Hash(x);
for(int i=head[key];i!=-1;i=g[i].nxt){
if(g[i].x==x){g[i].s++;return;}
}g[cnt].s=1; g[cnt].x=x;
g[cnt].nxt=head[key]; head[key]=cnt++;
}
int search(int x){
int key=Hash(x);
for(int i=head[key];i!=-1;i=g[i].nxt){
if(g[i].x==x)return g[i].s;
}return 0;
}
void init(){cnt=0;memset(head,-1,sizeof(head));ans=0;}
int main(){
for(int i=1;i<=100;i++)x[i]=i*i;
while(~scanf("%d%d%d%d",&a,&b,&c,&d)){
if(a*b>0&&b*c>0&&c*d>0){puts("0");continue;}init();
for(int i=1;i<=100;i++)for(int j=1;j<=100;j++)insert(x[i]*a+x[j]*b);
for(int i=1;i<=100;i++)for(int j=1;j<=100;j++)ans+=search(-x[i]*c-x[j]*d);
printf("%lld\n",ans<<4);
}return 0;
}

  

HDU 1496 Equations(哈希表)的更多相关文章

  1. hdu 1496 Equations hash表

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

  2. hdu 1496 Equations

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

  3. Equations HDU - 1496(哈希的应用)

    Problem Description Consider equations having the following form: a*x1^2+b*x2^2+c*x3^2+d*x4^2=0 a, b ...

  4. 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 ...

  5. 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 ...

  6. HDU - 1496 Equations (hash)

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

  7. hdu acm 1425 sort(哈希表思想)

    sort Time Limit: 6000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

  8. hdu 5183. Negative and Positive (哈希表)

    Negative and Positive (NP) Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 65536/65536 K (Ja ...

  9. HDU4887_Endless Punishment_BSGS+矩阵快速幂+哈希表

    2014多校第一题,当时几百个人交没人过,我也暴力交了几发,果然不行. 比完了去学习了BSGS才懂! 题目:http://acm.hdu.edu.cn/showproblem.php?pid=4887 ...

随机推荐

  1. Python学习5,三级菜单实例

    _author_ = "Happyboy" data = { '北京':{ "昌平":{ "沙河":["Happyboy" ...

  2. Leetcode 664.奇怪的打印机

    奇怪的打印机 有台奇怪的打印机有以下两个特殊要求: 打印机每次只能打印同一个字符序列. 每次可以在任意起始和结束位置打印新字符,并且会覆盖掉原来已有的字符. 给定一个只包含小写英文字母的字符串,你的任 ...

  3. Android记事本07

    昨天: activity横竖屏切换的生命周期 今天: Anr异常的原因和解决方案 遇到的问题: 无.

  4. regex & tab spaces

    regex & tab spaces txt file format let x = `2018-10-20a2018-10-20a2018-10-20a`; x.replace(/a/ig, ...

  5. C++ Programming with TDD之一:GMOCK框架简介

    所谓测试驱动开发,英文全称Test-Driven Development,简称TDD,是一种不同于传统软件开发流程的新型的开发方法.就是在明确要开发某个功能后,首先思考如何对这个功能进行测试,并完成测 ...

  6. 【bzoj4894】天赋 矩阵树定理

    题目描述 小明有许多潜在的天赋,他希望学习这些天赋来变得更强.正如许多游戏中一样,小明也有n种潜在的天赋,但有一些天赋必须是要有前置天赋才能够学习得到的.也就是说,有一些天赋必须是要在学习了另一个天赋 ...

  7. SecureCRT配置设置

    颜色设置   参考: http://blog.csdn.net/zklth/article/details/8937905 配置导入.导出   参考: http://jingyan.baidu.com ...

  8. java中的URLEncoder.encode对应JS中用decodeURIComponent,js和java编码,解码

    用get请求传中文,经常搞到乱码,这几天搞搞这个东西,总结一下,以方便以后处理这类的问题. Java代码中的URLEncoder.encode方法和JS的encodeURIComponent功能差不多 ...

  9. DP———1.最大子连续子序列和

    最大连续子序列 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Sub ...

  10. nginx tomcat负载均衡 使用redis session共享

    环境准备 1.准备一台nginx服务器 ip192.168.1.133 端口81 安装过程: #首先安装依赖: yum -y install gcc-c++ yum -y install pcre p ...