思路:这题好像以前有类似的讲过,我们把等式移一下,变成 -(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. c++ 函数返回研究[转]

    一,c++函数的返回分为以下几种情况 1)主函数main的返回值:这里提及一点,返回0表示程序运行成功. 2)返回非引用类型:函数的返回值用于初始化在跳用函数出创建的临时对象.用函数返回值初始化临时对 ...

  2. LeetCode——Sqrt(x)

    Description: Implement int sqrt(int x). Compute and return the square root of x. 好好学习数学还是非常有用的,牛顿迭代法 ...

  3. 【Android N 7.1.1】 锁屏之上显示Toast

    package com.android.systemuirom.keyguard; import android.content.Context; import android.view.Gravit ...

  4. 字符串处理(String)

    字符串类型(String类)需要注意的几个函数: 1.字符串的连接.一般而言,Java不允许运算符直接应用到String对象,唯一的例外是"+"运算符,它用来连接两个字符串,产生一 ...

  5. MySQL数据库连接池导致页面登录无法查询问题解决过程

    环境为tomcat+mysql 页面卡在登录界面或者登录后点击查询卡死,tomcat日志 连接池不可达 原因连接池不可用 解决办法 停止tomcat然后等待主机所有连接mysql的链接完全关闭再启动t ...

  6. ubuntu16.04下用笔记本摄像头和ROS编译运行ORB_SLAM2的单目AR例程

    要编译ORB_SLAM2的ROS例程首先需要安装ROS,以及在ROS下安装usb_cam驱动并调用,最后搭建ORB_SLAM2. 1.ROS的安装 我的电脑安装的是ubuntu16.04系统,所以我安 ...

  7. Fast and Accurate Traffic Matrix Measurement Using Adaptive Cardinality Counting

    paper-CaiPan.pdf http://conferences.sigcomm.org/sigcomm/2005/paper-CaiPan.pdf

  8. mysql float 浮点型

    定点数类型 DEC等同于DECIMAL 浮点类型:FLOAT DOUBLE 作用:存储薪资.身高.体重.体质参数等 m,d 都是设置宽度 =============================== ...

  9. IOS 自己定义UITableView

    依据不同须要,须要使用tableview的结构,可是里面每个cell,又须要自己的样式.所以学习了一下如何把自定义的cell加到tableview里面 首先要自己创建一个类,继承UITableView ...

  10. LeetCode——Palindrome Number

    Determine whether an integer is a palindrome. Do this without extra space. Some hints: Could negativ ...