HDU 1496 Equations(哈希表)
【题目链接】 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(哈希表)的更多相关文章
- hdu 1496 Equations hash表
hdu 1496 Equations hash表 题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1496 思路: hash表,将原来\(n^{4}\)降 ...
- hdu 1496 Equations
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1496 Equations Description Consider equations having ...
- 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 ...
- 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 ...
- 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 ...
- HDU - 1496 Equations (hash)
题意: 多组测试数据. 每组数据有一个方程 a*x1^2 + b*x2^2 + c*x3^2 + d*x4^2 = 0,方程中四个未知数 x1, x2, x3, x4 ∈ [-100, 100], 且 ...
- hdu acm 1425 sort(哈希表思想)
sort Time Limit: 6000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- hdu 5183. Negative and Positive (哈希表)
Negative and Positive (NP) Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 65536/65536 K (Ja ...
- HDU4887_Endless Punishment_BSGS+矩阵快速幂+哈希表
2014多校第一题,当时几百个人交没人过,我也暴力交了几发,果然不行. 比完了去学习了BSGS才懂! 题目:http://acm.hdu.edu.cn/showproblem.php?pid=4887 ...
随机推荐
- 孤荷凌寒自学python第四十四天Python操作 数据库之准备工作
孤荷凌寒自学python第四十四天Python操作数据库之准备工作 (完整学习过程屏幕记录视频地址在文末,手写笔记在文末) 今天非常激动地开始接触Python的数据库操作的学习了,数据库是系统化设计 ...
- 如何将自己写的代码上传到github上
忙活了一下午终于成功把代码上传到github上. 接下来就是我上传代码的步骤: ①首先注册github账号,登录,创建新仓库 ,点击+,点击new repository 得到如下页面,填写仓库名,自己 ...
- React跨域问题解决
https://segmentfault.com/q/1010000012732581 非跨域问题报错 -rpccorsdomain="http://localhost:3000" ...
- Codeforces Round #327 (Div2) A~E
CodeForces 591A 题意:在距离为L的两端A,B,相向发射魔法,a(以P1的速度)-->B,A<--b(以P2的速度).假设a-->B,途中相遇,则返回到原点A<- ...
- 二分查找树按照key值划分
#include <iostream>#include <vector>#include <algorithm>#include <string>#in ...
- SpringMVC<一> 基本结构与配置
刚刚踏入SpringMVC的学习,有一定Strust2的使用经验,边看书看博客,边总结,如有不对的地方还希望各位大佬多多指正. Spring 响应过程与结构 (1)用户在客户端发送一个HTTP请求,W ...
- vue vscode 开始
E:\Html\4 Vue版>npm config set registry https://registry.npm.taobao.org E:\Html\4 Vue版>npm i &g ...
- Win10 WSL Ubuntu18.04 编译安装MySQL5.7
---恢复内容开始--- 在win10 商店中选择 ubuntu18.04 下载地址 http://dev.mysql.com/downloads/mysql/ wget https://cdn.my ...
- windows 10 change default program bug
windows 10 change default program bug https://www.isumsoft.com/windows-10/how-to-change-or-set-defau ...
- 【bzoj5047】空间传送装置 堆优化Dijkstra
题目描述 n个点e条边的有向图,每条边是m种类型之一.第i种类型在第x时刻通过所花费的时间为$(a_i*x+b_i)\mod c_i+d_i$.可以在某个点停留.问:在s时刻从1号点出发,到达每个点所 ...