poj1840
来源:互联网 发布:海战网络手游哪个好玩 编辑:程序博客网 时间:2024/06/10 12:11
题意:求解五元三次方程在[-50,50]内的非零整数解
a*x1^3+b*x2^3+c*x3^3+d*x4^3+e*x5^3=0
求解的个数
首先想法:枚举
但是100^5,呵呵...
所以可以将方程变形:
c*x3^3+d*x4^3+e*x5^3=-a*x1^3-b*x2^3
这样,只要先预处理-a*x1^3-b*x2^3的个数,让后用数组存下来
对于负数,直接加上25000000即可,注意数组不要用int会报空间,可以用short
让后暴力枚举x3,4,5即可
#include<stdio.h>#include<string.h>#define N 25000000#define sqr(X) (X*X*X)#define rep(i,l,r) for(int i=l;i<=r;++i)short s[25000001];int a,b,c,d,e,cnt=0;inline int rp(int x){if(x<0) x+=N;return x;}int main(){for(;~scanf("%d%d%d%d%d",&a,&b,&c,&d,&e);cnt=0){memset(s,0,sizeof s);rep(i,-50,50) if(i)rep(j,-50,50) if(j) s[rp(-sqr(i)*a-sqr(j)*b)]++;rep(i,-50,50) if(i)rep(j,-50,50) if(j)rep(k,-50,50) if(k) cnt+=s[rp(sqr(i)*c+sqr(j)*d+sqr(k)*e)];printf("%d\n",cnt);}}
1 0
- poj1840
- poj1840
- POJ1840
- poj1840
- POJ1840
- poj1840
- poj1840
- poj1840
- poj1840
- poj1840
- poj1840
- poj1840
- POJ1840
- poj1840--Eqs
- poj1840 Eqs
- poj1840 Eqs
- POJ1840 哈希表
- Eqs poj1840
- 使用retrofit框架的网络请求方法使用例子,同时+MVP +rxjava + rxandroid使用
- 数据结构实验之查找二:平衡二叉树
- Java多线程系列--“JUC锁”06之 Condition条件 (r)
- 292. Nim Game
- 如何防止重复发送 Ajax 请求?
- poj1840
- CodeForces 653A Bear and Three Balls 【sort+去重(unique)】
- 【挖坑记】JZOJ 4727 挺进
- 【javascript】prototype继承
- Java多线程系列--“JUC锁”07之 LockSupport (r)
- 红黑树浅析
- 382. Linked List Random Node
- 142.leetcode Linked List Cycle II(medium)[有环链表]
- Primary IDE channel no 80 conductor cable installed