【题目链接】 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. nodejs下载图片到本地,根据百度图片查找相应的图片,通过nodejs保存到本地文件夹

    根据百度图片查找相应的图片:输入图片关键字,输入图片数量(默认是30条),通过nodejs将批量保存图片到本地文件夹. 代码已上传到github上:代码github的地址 下载后进去back-end: ...

  2. a链接点击下载图片到本地(php)

    $url="http://pan.baidu.com/share/qrcode?w=150&h=150&url=http://gandao.my".U('Quest ...

  3. 孤荷凌寒自学python第三十三天python的文件操作初识

     孤荷凌寒自学python第三十三天python的文件操作初识 (完整学习过程屏幕记录视频地址在文末,手写笔记在文末) 今天开始自学python的普通 文件操作部分的内容. 一.python的文件打开 ...

  4. Code Blocks中配置OpenGL方法

    关于在Code Blocks中配置OpenGL的方法,在网上一直没有找到实用的方法,后来在马龙师兄的帮助下终于配置成功了,现把配置过程记录如下. (1)下载codeblocks,最好是带mingw的版 ...

  5. web服务器集群session同步

    在做了web集群后,你肯定会首先考虑session同步问题,因为通过负载均衡后,同一个IP访问同一个页面会被分配到不同的服务器上,如果session不同步的话,一个登录用户,一会是登录状态,一会又不是 ...

  6. WebIDE

    1 1 1 WebIDE 是什么? WebIDE 是 一款在线集成开发环境( Integrated Development Environment ). 开发者只需要一个浏览器就可以编写代码,并在We ...

  7. Nginx与Tomcat集成

    Nginx用来处理静态页面的请求,JSP交给Tomcat处理 安装JDK 安装后,配置好JAVA_HOME和PATH Mac查看JAVA_HOME路径的方法:/usr/libexec/java_hom ...

  8. APIO2017游记

    铁牌选手爆零滚粗记QAQ........ CCF说不让讨论APIO相关内容不过现在应该没事了吧QAQ day0:上午还在学校填清北夏令营的表,下午上火车去北京,晚上颓颓颓...... day1:上午网 ...

  9. ci动态设置config配置

    $this->config->set_item('cookie', 'item_value');echo $this->config->item('cookie');

  10. poj 3648 Wedding 2-SAT问题入门题目

    Description Up to thirty couples will attend a wedding feast, at which they will be seated on either ...