HDU 1496
题目出处:HDU OJ 1496 http://acm.hdu.edu.cn/showproblem.php?pid=1496
为了练习Hash,特定采用了杭电自带的分类列表http://acm.hdu.edu.cn/problemclass.php?id=64
本题采用暴搜貌似也能AC,在这里就不再给出了.
ps: 偏移量设置: a x1^2 + b x2^2 的取值范围 [-1000000,1000000]; 因此偏移量选择1000000即可
累积计数,可能出现多组数对的结果相同
第21行 b1[t1 + OFFSET]++; 需要累加,而不是 b1[t1 + OFFSET] =1;
代码如下:
#include <iostream>
#include <cmath>
#include <cstring>
using namespace std; #define OFFSET 1000001 int b1[]; long findA(int a,int b, int c, int d)
{ memset(b1,,sizeof(b1));
long t1,t2,count=;
int i,j;
for(i=;i<=;i++)
{
for(j=;j<=;j++)
{
t1 = a*(i*i) + b*(j*j);
b1[t1 + OFFSET]++; // 加入偏移量,以免越界
}
}
for(i=;i<=;i++)
{
for(j=;j<=;j++)
{
t2 = c*(i*i) +d*(j*j);
if(b1[OFFSET - t2]>) count+=b1[OFFSET-t2]; //可以产生同一个结果的数对可能不止一个
}
}
return count;
} int main()
{
int a,b,c,d;
while(cin>>a>>b>>c>>d && a && b && c && d)
{
if((a> && b> && c> && d>)||(a< && b< && c< && d<)) //逻辑加速,边间判断
cout<<<<endl;
else
cout<<findA(a,b,c,d)*<<endl;
}
return ;
}
HDU 1496的更多相关文章
- 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 ...
- HDU 1496 Equations(哈希表)
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=1496 [题目大意] 给出一个方程ax1^2+bx2^2+cx3^2+dx4^2=0,求-100到1 ...
- 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 Train Problem I 火车问题1(桟,水)
题意: 给出两个串,串中的数字i 代表编号为i的火车进入车站的顺序,车站如桟一样,先进后出.第二个串是火车出站的顺序,问若按照第一个串那样进站,是否有可能如第二个串一样的出站顺序?火车顶多9辆,即1- ...
- Equations(hdu 1496 二分查找+各种剪枝)
Equations Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- HDU - 1496 Equations (hash)
题意: 多组测试数据. 每组数据有一个方程 a*x1^2 + b*x2^2 + c*x3^2 + d*x4^2 = 0,方程中四个未知数 x1, x2, x3, x4 ∈ [-100, 100], 且 ...
- hdu 1496 hash
hash?判重,是否一样?相等?等式!没有想到,这次题做玩后,学到了HASH这一功能!当数据量在数组允许大小范围内时候即可!判断等式俩边是否相等,从而获得解的个数!从复杂度,n*m*k****,降到 ...
随机推荐
- bundle install 老是中断,可以在gemfile里面把source换成taobao源,可以自动安装
bundle install 老是中断,可以在gemfile里面把source换成taobao源,可以自动安装
- Python中的列表生成式和多层表达式
Python中的列表生成式和多层表达式 如何生成[1x1, 2x2, 3x3, ..., 10x10]的列表? L=[]; ,): L.append(x*x) print L print (" ...
- Etcd的基本使用
etcd 是 CoreOS 团队于 2013 年 6 月发起的开源项目,它的目标是构建一个高可用的分布式键值(key-value)数据库,基于 Go 语言实现,内部采用 raft 协议作为一致性算法. ...
- Python进程监控-MyProcMonitor
psutil api文档: http://pythonhosted.org/psutil/ api 测试 #! /usr/bin/env python # coding=utf-8 import ps ...
- elasticsearch must和should组合查询
{"query": { "bool": { "should": [ {"bool": { "must" ...
- AspectJ、Spring与AOP的关系
- C#的ComboBox学习使用2018.08.03
ComboBox是一个有下拉列表的文本显示框,其text为当前的文本,item属性为项 comboBox1.Items.Add("); id = comboBox1.Text; 可以采用se ...
- 钉钉开发笔记(六)使用Google浏览器做真机页面调试
注: 参考文献:https://developers.google.com/web/ 部分字段为翻译文献,水平有限,如有错误敬请指正 步骤1: 从Windows,Mac或Linux计算机远程调试And ...
- mysql sql left right inner join区别及效率比较
一.Join语法概述 join 用于多表中字段之间的联系,语法如下: ... FROM table1 INNER|LEFT|RIGHT JOIN table2 ON conditiona table1 ...
- 303. Range Sum Query 范围求和系列
Immutable [抄题]: Given an integer array nums, find the sum of the elements between indices i and j (i ...