思路:这题好像以前有类似的讲过,我们把等式移一下,变成 -(a1*x1^3 + a2*x2^3)== a3*x3^3 + a4*x4^3 + a5*x5^3,那么我们只要先预处理求出左边的答案,然后再找右边是否也能得到就行了,暴力的复杂度从O(n^5)降为O(n^3 + n^2)。因为左式范围-12500000~12500000,所以至少开12500000 * 2的空间,用int会爆,这里用short。如果小于0要加25000000,这样不会有重复的答案,算是简单的hash?

代码:

#include<map>
#include<ctime>
#include<cmath>
#include<cstdio>
#include<iostream>
#include<algorithm>
#define ll long long
#define ull unsigned long long
using namespace std;
const int maxn = + ;
const int seed = ;
const int MOD = ;
const int INF = 0x3f3f3f3f;
short num[ * + ];
int main(){
int base = * ;
int a1, a2, a3, a4, a5;
while(~scanf("%d%d%d%d%d", &a1, &a2, &a3, &a4, &a5)){
memset(num, , sizeof(num));
for(int i = -; i <= ; i++){
if(!i) continue;
for(int j = -; j <= ; j++){
if(!j) continue;
int sum = -(a1 * i * i * i + a2 * j * j * j);
if(sum < ) sum += base;
num[sum]++;
}
}
int ans = ;
for(int i = -; i <= ; i++){
if(!i) continue;
for(int j = -; j <= ; j++){
if(!j) continue;
for(int k = -; k <= ; k++){
if(!k) continue;
int sum = a3 * i * i * i + a4 * j * j * j + a5 * k * k * k;
if(sum < ) sum += base;
ans += num[sum];
}
}
}
printf("%d\n",ans);
}
return ;
}

POJ 1840 Eqs(乱搞)题解的更多相关文章

  1. poj 1840 Eqs (hash)

    题目:http://poj.org/problem?id=1840 题解:http://blog.csdn.net/lyy289065406/article/details/6647387 小优姐讲的 ...

  2. POJ 1840 Eqs 解方程式, 水题 难度:0

    题目 http://poj.org/problem?id=1840 题意 给 与数组a[5],其中-50<=a[i]<=50,0<=i<5,求有多少组不同的x[5],使得a[0 ...

  3. POJ 1840 Eqs

    Eqs Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 15010   Accepted: 7366 Description ...

  4. POJ 1840 Eqs 二分+map/hash

    Description Consider equations having the following form: a1x13+ a2x23+ a3x33+ a4x43+ a5x53=0 The co ...

  5. POJ 1840 Eqs 暴力

      Description Consider equations having the following form: a1x13+ a2x23+ a3x33+ a4x43+ a5x53=0 The ...

  6. poj 1840 Eqs 【解五元方程+分治+枚举打表+二分查找所有key 】

    Eqs Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 13955   Accepted: 6851 Description ...

  7. POJ 1840 Eqs(hash)

    题意  输入a1,a2,a3,a4,a5  求有多少种不同的x1,x2,x3,x4,x5序列使得等式成立   a,x取值在-50到50之间 直接暴力的话肯定会超时的   100的五次方  10e了都 ...

  8. “盛大游戏杯”第15届上海大学程序设计联赛夏季赛暨上海高校金马五校赛题解&&源码【A,水,B,水,C,水,D,快速幂,E,优先队列,F,暴力,G,贪心+排序,H,STL乱搞,I,尼姆博弈,J,差分dp,K,二分+排序,L,矩阵快速幂,M,线段树区间更新+Lazy思想,N,超级快速幂+扩展欧里几德,O,BFS】

    黑白图像直方图 发布时间: 2017年7月9日 18:30   最后更新: 2017年7月10日 21:08   时间限制: 1000ms   内存限制: 128M 描述 在一个矩形的灰度图像上,每个 ...

  9. POJ 3077-Rounders(水题乱搞)

    Rounders Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7697   Accepted: 4984 Descript ...

随机推荐

  1. weblogic新漏洞学习cve-2017-10271

    一.原理: 很明显啦,readobject又出来背锅了,一个XML的反序列化漏洞导致的命令执行. 具体原理我看不懂java代码的我也只能学习别人的分析.给出一篇参考文章,写的非常详细: 漏洞原理 二. ...

  2. mysql客户端不能插入中文字符

    问题:输入中文报错:Incorrect string value 步骤: 1.查看MySQL编码设置 show variables like '%character%'; 2.重新设置编码(注意:ut ...

  3. javascript飞机大战-----007爆炸效果

    要检验什么时候碰撞,我们必须了解什么时候不相撞.以上四种情况是不相撞的时候 首先在引擎里面写好什么时候碰撞什么时候不碰撞 /* 游戏引擎 */ var Engine = { //刚开始的游戏状态 ga ...

  4. Object 对象有哪些方法?

    这个不看还真不一定能说全,请养成良好的阅读源码和JDK文档的习惯. 总结一下:一共11个,wait的3个+notify的2个,hashCode和equals还有toString共3个,然后clone和 ...

  5. Mssql备份失败

    Mssql备份失败出现如下提示 备份时先删除默认的备份设备,自己选择路径

  6. AttributeError: 'module' object has no attribute 'face'

    报错 raceback (most recent call last): File "D:/work/python/face_ai/predict.py", line 41, in ...

  7. code sandbox & mlflow

    https://codesandbox.io/ https://www.jianshu.com/p/d70b25bf3cf4 https://my.oschina.net/u/2306127/blog ...

  8. 用MongoDB取代RabbitMQ(转)

    原文:http://blog.nosqlfan.com/html/3223.html RabbitMQ是当成应用比较广泛的队列服务系统,其配套的客户端和监控运维方案也比较成熟.BoxedIce的队列服 ...

  9. Xshell连接阿里云Centos6.8

    由于我将xshell更新到了Xshell v5.0 Build 1332,在连接阿里云服务器的时候遇到了一些问题. 以前我登录到服务器的时候直接输入登录密码就行了,但是现在由于openssh服务器类型 ...

  10. 模仿Masonary写一个计算器

    1.CaculatorMaker @interface CaculatorMaker : NSObject @property(nonatomic,assign)int result; -(Cacul ...