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 ...
随机推荐
- STL之set&multiset使用简介
关于set,必须说明的是set关联式容器.set作为一个容器也是用来存储同一数据类型的数据类型,并且能从一个数据集合中取出数据,在set中每个元素的值都唯一,而且系统能根据元素的值自动进行排序.应该注 ...
- TOJ 3046: 招商银行网络系统
3046: 招商银行网络系统 Time Limit(Common/Java):1000MS/3000MS Memory Limit:65536KByteTotal Submit: 12 ...
- 201621123033 《Java程序设计》第9周学习总结
第九次作业 1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结集合与泛型相关内容. 1.2 选做:收集你认为有用的代码片段 //stream(),filter(),collect() ...
- hadoop2.5.2学习及实践笔记(六)—— Hadoop文件系统及其java接口
文件系统概述 org.apache.hadoop.fs.FileSystem是hadoop的抽象文件系统,为不同的数据访问提供了统一的接口,并提供了大量具体文件系统的实现,满足hadoop上各种数据访 ...
- cfq调度器
cfq调度是block层最复杂的一个调度器,主要思想是是说每个进程平均享用IO带宽,实现方法是在时间上对进程进行划分,以此达到平均占用IO的目的.带着几个问题去看cfq 1)现在进程来了之后,是插入到 ...
- hdu 1811 Rank of Tetris (拓扑 & 并查集)
Rank of Tetris Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- IPv4地址分类及特征
IPv4地址分类及特征 IP地址后斜杠和数字代表的意思 其中有这样一个IP地址的格式:IP/数字,例如:111.222.111.222/24 这种格式平时在内网中用的不多,所以一下子看不懂,最后查了资 ...
- [洛谷P4841]城市规划
题目大意:求$n$个点的带标号的无向连通图的个数 题解:令$F(x)$为带标号无向连通图个数生成函数,$G(x)$为带标号无向图个数生成函数 那么$G(x) = \sum_{i=0}^{\infty} ...
- 【CF Edu 28 A. Curriculum Vitae】
time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...
- js加解密的算法
//字符串和数字互转 var str="a" var r = str.charCodeAt(0); //97 10进制 console.log(r); var t=String.f ...