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 ...
随机推荐
- 浅析HTTPS与SSL原理
版权声明:本文由盛旷 原创文章,转载请注明出处: 文章原文链接:https://www.qcloud.com/community/article/134 来源:腾云阁 https://www.qclo ...
- 腾讯云CMQ消息队列在Linux环境下的使用
版权声明:本文由李少华原创文章,转载请注明出处: 文章原文链接:https://www.qcloud.com/community/article/76 来源:腾云阁 https://www.qclou ...
- maven项目使用SOLR时报 previously initiated loading for a different type with name "javax/servlet/http/HttpServletRequest" 错的解决方法
环境:Apache solr4.8,maven3,IntellijIDEA 想在项目中使用solr 在pom.xml文件中添加了solr的依赖 solr-core,solrj 和solr-dataim ...
- 【BZOJ3470】Freda’s Walk 概率与期望
[BZOJ3470]Freda’s Walk Description 雨后的Poetic Island空气格外清新,于是Freda和Rainbow出来散步. Poetic Island的交通可以看作一 ...
- 在ListView中嵌套ListView的事件处理
十分感谢此作者,以及作者的作者,让我卡了一星期的问题解决了!!http://blog.csdn.net/hutengfei0701/article/details/8956284谢谢http://my ...
- tpcc-mysql安装、使用、结果解读
请点击:http://www.aikaiyuan.com/8687.html 错误处理: ln -s /usr/local/mysql/lib/libmysqlclient.so. /usr/lib6 ...
- JAVA内存构成详解
java memory = direct memory(直接内存) + jvm memory(MaxPermSize +Xmx) 1)直接内存跟堆 直接内存则是一块由程序本身管理的一块内存空间,它 ...
- SVN 配置和使用
SVN使用环境 使用SVN管理源代码,必须有2套环境 服务器 用来存储客户端上传的源码 一般都是在Windows环境下安装Visual SVN Server 客户端 用来提交.回退.修改.下载等操作 ...
- centos6.8 环境一键安装包 nginx配置thinkphp5
---恢复内容开始--- lnmp1.4 一键安装包 nginx配置thinkphp5 环境:Nginx1.12.1 PHP5.6 Coentos6.8 修改网站配置文件 ser ...
- docker 2375 vulnerability and self-signatuer certifications
Docker暴露2375端口,引起安全漏洞 今天有小伙伴发现Docker暴露出2375端口,引起了安全漏洞.我现在给大家介绍整个事情的来龙去脉,并告诉小伙伴们,怎么修复这个漏洞. 为了实现集群管理,D ...