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****,降到 ...
随机推荐
- linux shell find
find / -ctime +365 ! -name "*.bat" -exce rm -rf {} \;
- C语言增量内存申请 realloc
void* realloc (void* ptr, size_t size); Reallocate memory block Changes the size of the memory block ...
- Invalid command 'Header', perhaps misspelled or defined by a module not included in the server configuration
在Apache的配置文件 httpd.conf 中开启 LoadModule headers_module modules/mod_headers.so 即可解决这个问题.
- mysql主从错误180301
Fatal error: The slave I/O thread stops because master and slave have equal MySQL server ids; these ...
- poj1067-取石子游戏 (威佐夫博弈)
http://poj.org/problem?id=1067 取石子游戏 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 36 ...
- IDEA06 代码规范检测插件之Alibaba Java Coding Guidelines
1 官方资料 1.1 官方介绍 https://mp.weixin.qq.com/s/IbibsXlWHlM59kfXJqRvZA#rd 1.2 github地址 https://github.com ...
- 2.spark-streaming实战
park Streaming--实战篇 摘要: Sprak Streaming属于Saprk API的扩展,支持实时数据流(live data streams)的可扩展,高吞吐(hight- ...
- radio后的input框数据传递
<input type="radio" name="limit_type" value="total">活动期间,每个手机号可抽 ...
- Linux 上安装 rlwrap
1.安装rlwrap的初衷; 2.安装rlwrap工具和遇到的问题; 3.使用rlwrap 工具; 1.安装rlwrap的初衷: 在Windows 下使用SQLPLUS都是可以使用上下左右方向键前后左 ...
- 第一次用FontLad~
FontLad 是一款制作字体的工具 使用流程: 1. 下载.安装软件FontLab Studio2. File->New菜单,创建一个工程文件,会自动创建一个ASCII码表对应的字体表3. ...