POJ 1840 Eqs(乱搞)题解
思路:这题好像以前有类似的讲过,我们把等式移一下,变成 -(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(乱搞)题解的更多相关文章
- poj 1840 Eqs (hash)
题目:http://poj.org/problem?id=1840 题解:http://blog.csdn.net/lyy289065406/article/details/6647387 小优姐讲的 ...
- POJ 1840 Eqs 解方程式, 水题 难度:0
题目 http://poj.org/problem?id=1840 题意 给 与数组a[5],其中-50<=a[i]<=50,0<=i<5,求有多少组不同的x[5],使得a[0 ...
- POJ 1840 Eqs
Eqs Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 15010 Accepted: 7366 Description ...
- POJ 1840 Eqs 二分+map/hash
Description Consider equations having the following form: a1x13+ a2x23+ a3x33+ a4x43+ a5x53=0 The co ...
- POJ 1840 Eqs 暴力
Description Consider equations having the following form: a1x13+ a2x23+ a3x33+ a4x43+ a5x53=0 The ...
- poj 1840 Eqs 【解五元方程+分治+枚举打表+二分查找所有key 】
Eqs Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 13955 Accepted: 6851 Description ...
- POJ 1840 Eqs(hash)
题意 输入a1,a2,a3,a4,a5 求有多少种不同的x1,x2,x3,x4,x5序列使得等式成立 a,x取值在-50到50之间 直接暴力的话肯定会超时的 100的五次方 10e了都 ...
- “盛大游戏杯”第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 描述 在一个矩形的灰度图像上,每个 ...
- POJ 3077-Rounders(水题乱搞)
Rounders Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7697 Accepted: 4984 Descript ...
随机推荐
- js 数组函数
Array.prototype.join Array.prototype.reverse Array.prototype.sort Array.prototype.concat Array.proto ...
- 启动Solr时报 _version_ field must exist in schema 错误的解决方法
Solr启动时报 org.apache.solr.common.SolrException:org.apache.solr.common.SolrException: Unable to use up ...
- 字符串函数---atof()函数详解
atof()函数 atof(),是C 语言标准库中的一个字符串处理函数,功能是把字符串转换成浮点数,所使用的头文件为<stdlib.h>.该函数名是 “ascii to floating ...
- PHP的线性安全和非线性安全的区别
从2000年10月20日发布的第一个Windows版的PHP3.0.17开始的都是线程安全的版本,这是由于与Linux/Unix系统是采用多进程的工作方式不同的是Windows系统是采用多线程的工作方 ...
- java观察者(Observer)模式
观察者模式: 试想,在电子商务网站上,一个用户看中了一件一份,但是当时衣服的价格太贵,你需要将衣服收藏,以便等衣服降价时自动通知该用户.这里就是典型的观察模式的例子. 1.观察者模式的 ...
- spring自定义事务同步器(二):借助redisson实现自己的同步器
1. 借助redis的java客户端redisson实现自己的事物同步器 @Override public void lockWithinCurrentTransaction(Object key) ...
- Keras-图片预处理
图片预处理 图片生成器ImageDataGenerator keras.preprocessing.image.ImageDataGenerator(featurewise_center=False, ...
- arthas使用介绍
背景: 一次线上问题的综合排查排查,两个相同的系统的某个模块,数据量更少的系统查询更慢. 先说下整体思路: 查看系统整理负载,网络有100左右毫秒的延迟,看起来影响不大 查看正序运行整体情况,一次查询 ...
- (转)《SSO CAS单点系列》之 实现一个SSO认证服务器是这样的!
上篇我们引入了SSO这个话题<15分钟了解SSO是个什么鬼!>.本篇我们一步步深入分析SSO实现机理,并亲自动手实现一个线上可用的SSO认证服务器!首先,我们来分析下单Web应用系统登录登 ...
- 基于struts2框架-自定义身份证号验证器
自定义拦截器的步骤: 1.定义一个验证器的类: > 自定义的验证器都需要实现 Validator接口. > 可以选择继承 ValidatorSupport 或 FieldValidato ...