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 ...
随机推荐
- nodejs下载图片到本地,根据百度图片查找相应的图片,通过nodejs保存到本地文件夹
根据百度图片查找相应的图片:输入图片关键字,输入图片数量(默认是30条),通过nodejs将批量保存图片到本地文件夹. 代码已上传到github上:代码github的地址 下载后进去back-end: ...
- Wordpress 为用户或角色 role 添加 capabilities(权限)
首先查看角色具有哪些权限: $admin_role_set = get_role( 'administrator' )->capabilities; $author_role_set = get ...
- Opencv2.4.13.6安装包
这个资源是Opencv2.4.13.6安装包,包括Windows软件包,Android软件包,IOS软件包,还有opencv的源代码:需要的下载吧. 点击下载
- 软工实践 - 第十三次作业 Alpha 冲刺 (4/10)
队名:起床一起肝活队 组长博客:https://www.cnblogs.com/dawnduck/p/9980005.html 作业博客:班级博客本次作业的链接 组员情况 组员1(队长):白晨曦 过去 ...
- 使用Cookie保存用户和密码然后自动登录
login.html <!DOCTYPE html> <html lang="en"> <head> <meta charset=&quo ...
- 物联网第一次作业--我眼中的物联网——从认识RFID开始
无线射频识别技术(Radio FrequencyIdentification,简称:RFID)是一种非接触式的自动识别技术,其基本原理是利用射频信号和空间耦合(电感或电磁耦合)或雷达反射的传输特性,实 ...
- jquery select chosen 动态绑定值
$("#ddlMstData").find("option[value=" + data.MstKey + "]").attr(" ...
- MVC4.0 bug 神奇的是事情 bool 值变成了 onclick ,非常奇怪的
foreach (var item in ViewBag.PhotoGroupList) { // 这里很奇怪 item.IS_DISPLAY 是布尔值 如果直接写 @item.IS_DISPLAY ...
- 怎样把本地的jar包引入到maven工程里面
有些jar包在maven库里面查找不到,但是maven项目又有用到,此时最简单的方法就是把该jar包放到工程底下某个目录,然后在pom.xml里面配置dependency引入它. 具体如何操作呢? 假 ...
- Codeforces 932.B Recursive Queries
B. Recursive Queries time limit per test 2 seconds memory limit per test 256 megabytes input standar ...