HDU ACM 1496 Equations
Equations
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3978 Accepted Submission(s): 1602
a*x1^2+b*x2^2+c*x3^2+d*x4^2=0
a, b, c, d are integers from the interval [-50,50] and any of them cannot be 0.
It is consider a solution a system ( x1,x2,x3,x4 ) that verifies the equation, xi is an integer from [-100,100] and xi != 0, any i ∈{1,2,3,4}.
Determine how many solutions satisfy the given equation.
End of file.
#include<stdio.h>
#include<string.h>
#define MAXN 50001
int num[MAXN], store[MAXN]; int hash(int cur)
{
int temp = cur%MAXN;
if(temp < ) temp += MAXN;
while(num[temp] != && store[temp] != cur)
{
temp = (temp+)%MAXN;
}
return temp;
} int main()
{
// freopen("input.txt", "r", stdin);
int rate[], a, b, c, d, i, j, sum, temp, res;
for(i=; i<; ++i) rate[i] = i*i;
while(scanf("%d%d%d%d", &a, &b, &c, &d) != EOF)
{
if((a>&&b>&&c>&&d>) || (a<&&b<&&c<&&d<))
{
printf("0\n");
continue;
}
memset(num, , sizeof(num));
for(i=; i<; ++i)
for(j=; j<; ++j)
{
temp = a*rate[i]+b*rate[j];
res = hash(temp);
store[res] = temp;
num[res]++;
} sum = ; for(i=; i<; ++i)
for(j=; j<; ++j)
{
temp = -(c*rate[i]+d*rate[j]);
res = hash(temp);
sum += num[res];
} printf("%d\n", sum****);
}
return ;
}
HDU ACM 1496 Equations的更多相关文章
- hdu 1496 Equations
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1496 Equations Description Consider equations having ...
- hdu 1496 Equations hash表
hdu 1496 Equations hash表 题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1496 思路: hash表,将原来\(n^{4}\)降 ...
- hdu acm 1028 数字拆分Ignatius and the Princess III
Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ...
- 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 Equations (hash)
题意: 多组测试数据. 每组数据有一个方程 a*x1^2 + b*x2^2 + c*x3^2 + d*x4^2 = 0,方程中四个未知数 x1, x2, x3, x4 ∈ [-100, 100], 且 ...
- HDU ACM 题目分类
模拟题, 枚举1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 104 ...
- HDU 4569 Special equations(取模)
Special equations Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
随机推荐
- Android listview的item设定高度
在item的layout文件中,用android:layout_height设置item的高度.运行,高度设置无效. 解决办法: 给item设定minHeight,即可. -------------- ...
- 转:Android 获取Root权限
来自:http://blog.csdn.net/twoicewoo/article/details/7228940 import java.io.DataOutputStream; import an ...
- ios UICollectionView滑动时操作
点开UICollectionViewDelegate,发现有@protocol UICollectionViewDelegate <UIScrollViewDelegate>. 所以只要实 ...
- NDK(16)Jni中GetStaticFieldID和GetMethodID 中的类型标识串
env在GetStaticFieldID和GetMethodID 时,函数参数和返回值的类型要指定类型标识串,如: jmethodID init = env->GetMethodID(clz,& ...
- [HDOJ4578]Transformation(线段树,多延迟标记)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4578 四种操作:查询.加法.乘法.改数.应该是需要维护三个lazy标记,然后就是套路了.查询是区间内所 ...
- 转 Android中进入系统设置界面
Android软件时,常常需要打开系统设置或信息界面,来设置相关系统项或查看系统的相关信息,这时我们就可以使用以下语句来实现:(如打开“无线和网络设置”界面) Intent intent = new ...
- C#开发BHO插件UrlTrack
最近忽然突发奇想,想统计一下我最经常上的网站是哪些,并且在这些网站上都停留了多久.为此决定写一个BHO插件来做这件事. BHO(Browser Help Objects)是实现了特定接口(IObjec ...
- Oracle VM VirtualBox虚拟机安装系统
作为一个前端,必须要有自己的虚拟机,用于测试 IE6 .IE7浏览器. 要测试这两个浏览器,必须要是 Windows XP 系统才可以,这里我找到两个纯净版的 xp 系统 iso 镜像文件. http ...
- java6 新特新
JAVA6新特性介绍 1. 使用JAXB来实现对象与XML之间的映射 JAXB是Java Architecture for XML Binding的缩写,可以将一个Java对象转变成为XML格式, ...
- 1450. Russian Pipelines(spfa)
1450 水题 最长路 #include <iostream> #include<cstdio> #include<cstring> #include<alg ...