hdu 1496 && poj 1840 (简单哈希)
来源:互联网 发布:淘宝怎么写标题 编辑:程序博客网 时间:2024/06/06 20:13
Equations
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 5573 Accepted Submission(s): 2209
Problem Description
Consider equations having the following form:
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.
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.
Input
The input consists of several test cases. Each test case consists of a single line containing the 4 coefficients a, b, c, d, separated by one or more blanks.
End of file.
End of file.
Output
For each test case, output a single line containing the number of the solutions.
Sample Input
1 2 3 -41 1 1 1
Sample Output
390880
给出一个含有8个为知参数的等式 参数都是范围的
给出其中四个系数的值 求另外四个参数满足该等式的总可能数
首先将等式变性 a*x1^2+b*x2^2=-c*x3^2-d*x4^2
因为数据范围相对较小 所以可以通过两次循环用数组存储等式左边能够出现的所有情况的值
然后再通过两次循环 找出等式右边能够出现的值在数组中出现的情况数 将所有的情况数相加
#include <cstdio>#include <iostream>#include <cstring>#include <cmath>#include <algorithm>#include <string.h>#include <string>#define eps 1e-8#define op operator#define MOD 10009#define MAXN 2000100#define INF 0x7fffffff#define FOR(i,a,b) for(int i=a;i<=b;i++)#define FOV(i,a,b) for(int i=a;i>=b;i--)#define REP(i,a,b) for(int i=a;i<b;i++)#define REV(i,a,b) for(int i=a-1;i>=b;i--)#define MEM(a,x) memset(a,x,sizeof a)#define ll __int64using namespace std;int hs[MAXN];int main(){//freopen("ceshi.txt","r",stdin); int a,b,c,d; while(scanf("%d%d%d%d",&a,&b,&c,&d)!=EOF) { if(a>0&&b>0&&c>0&&d>0||a<0&&b<0&&c<0&&d<0) { puts("0"); continue; } MEM(hs,0); int ans=0; for(int i=1;i<=100;i++) for(int j=1;j<=100;j++) hs[a*i*i+b*j*j+1000010]++; for(int i=1;i<=100;i++) for(int j=1 ;j<=100;j++) { ans+=hs[-c*i*i-d*j*j+1000010]; } for(int i=1;i<=100;i++) for(int j=1 ;j<=100;j++) { hs[-c*i*i-d*j*j+1000010]=0; } printf("%d\n",ans*16); } return 0;}
Eqs
Time Limit: 5000MS Memory Limit: 65536KTotal Submissions: 12551 Accepted: 6148
Description
Consider equations having the following form:
a1x13+ a2x23+ a3x33+ a4x43+ a5x53=0
The coefficients are given integers from the interval [-50,50].
It is consider a solution a system (x1, x2, x3, x4, x5) that verifies the equation, xi∈[-50,50], xi != 0, any i∈{1,2,3,4,5}.
Determine how many solutions satisfy the given equation.
a1x13+ a2x23+ a3x33+ a4x43+ a5x53=0
The coefficients are given integers from the interval [-50,50].
It is consider a solution a system (x1, x2, x3, x4, x5) that verifies the equation, xi∈[-50,50], xi != 0, any i∈{1,2,3,4,5}.
Determine how many solutions satisfy the given equation.
Input
The only line of input contains the 5 coefficients a1, a2, a3, a4, a5, separated by blanks.
Output
The output will contain on the first line the number of the solutions for the given equation.
Sample Input
37 29 41 43 47
Sample Output
654
Source
Romania OI 2002
所需的数组变得更大 对内存要求高 把数组类型改为short 直接求解 参数不为0
#include <cstdio>#include <iostream>#include <cstring>#include <cmath>#include <algorithm>#include <string.h>#include <string>#define eps 1e-8#define op operator#define MOD 10009#define MAXN 25000010#define INF 0x7fffffff#define FOR(i,a,b) for(int i=a;i<=b;i++)#define FOV(i,a,b) for(int i=a;i>=b;i--)#define REP(i,a,b) for(int i=a;i<b;i++)#define REV(i,a,b) for(int i=a-1;i>=b;i--)#define MEM(a,x) memset(a,x,sizeof a)#define ll __int64using namespace std;short hs[MAXN];int main(){//freopen("ceshi.txt","r",stdin); int a,b,c,d,e; while(scanf("%d%d%d%d%d",&a,&b,&c,&d,&e)!=EOF) { MEM(hs,0); int ans=0; for(int i=-50;i<=50;i++) { if(i==0) continue; for(int j=-50;j<=50;j++) { if(j==0) continue; for(int k=-50;k<=50;k++) { if(k==0) continue; int sum=a*i*i*i+b*j*j*j+c*k*k*k; if(sum<0) sum+=25000000; hs[sum]++; } } } for(int i=-50;i<=50;i++) { if(i==0) continue; for(int j=-50;j<=50;j++) { if(j==0) continue; int sum=-d*i*i*i-e*j*j*j; if(sum<0) sum+=25000000; ans+=hs[sum]; } } printf("%d\n",ans); } return 0;}
0 0
- hdu 1496 && poj 1840 (简单哈希)
- poj 1840 简单哈希
- HDU 1496 Equations(简单哈希)
- hdu,poj博弈简单题
- hdu(poj)-2084(3176)-数塔-简单dp
- poj 1517 & hdu 1012 u Calculate e(简单阶乘)
- POJ 3505 && HDU 2341 Tower Parking(简单模拟)
- POJ 3349 简单哈希
- poj 2503 简单哈希
- HDU-1496-Equations && POJ-1840-Eqs (hash)
- POJ 1200 Crazy Search(简单哈希)
- POJ 2348& HDU 2147&HDU 1846&POJ 1067&HDU 1850 简单的博弈
- POJ 1840 Eqs(简单hash入门)
- poj 1840 简单hash。
- poj 1840 简单hash
- hdu-1392 Surround the Trees && poj Rope (简单凸包)
- hdu 1033 (简单)
- POJ 1573 && hdu 1035 Robot Motion【简单模拟】
- Eclipse内存优化 -Xms128m -Xmx512m 1
- 浏览器缩放造成的网页错位问题
- 联想笔记本一键安装win7系统
- VMProtect使用小计【二】 – 加壳查看
- 互联网协议入门(一)
- hdu 1496 && poj 1840 (简单哈希)
- 关于listview 的setOnItemClickListener失效问题
- 关于HbernateTemplate的简单用法
- DVFS简介
- ubuntu安装zend studio10.6.0
- 西安喜宝月子中心
- 开发者必须了解的10大跨平台移动开发工具
- struts2实现防止表单重复提交
- 深入浅出 Cocoa 之多线程 NSThread