poj 1840 哈希
| Time Limit: 5000MS | Memory Limit: 65536K | |
| Total Submissions: 14093 | Accepted: 6927 |
Description
a1x13+ a2x23+ a3x33+ a4x43+ a5x53=0
The coefficients are given integers from the interval [-50,50].
It is consider a solution a system (x1, x2, x3, x4, x5) that verifies the equation, xi∈[-50,50], xi != 0, any i∈{1,2,3,4,5}.
Determine how many solutions satisfy the given equation.
Input
Output
Sample Input
37 29 41 43 47
Sample Output
654
Source
#include<iostream> 49664K 610MS
#include<cstdio>
#include<cstring> using namespace std; short hash[25000001]; //hash[sum]表示值等于sum的的解的个数(多对1映射) int main() //用int会MLE<span id="transmark"></span>
{
int a1,a2,a3,a4,a5; //系数
scanf("%d%d%d%d%d",&a1,&a2,&a3,&a4,&a5);
{
memset(hash,0,sizeof(hash));
for(int x1=-50; x1<=50; x1++)
{
if(!x1)
continue;
for(int x2=-50; x2<=50; x2++)
{
if(!x2)
continue;
int sum=(a1*x1*x1*x1+a2*x2*x2*x2);
if(sum<0)
sum+=25000000;
hash[sum]++;
}
}
int num=0;
for(int x3=-50; x3<=50; x3++)
{
if(!x3)
continue;
for(int x4=-50; x4<=50; x4++)
{
if(!x4)
continue;
for(int x5=-50; x5<=50; x5++)
{
if(!x5)
continue;
int sum=a3*x3*x3*x3+a4*x4*x4*x4+a5*x5*x5*x5;
if(sum>12500000||sum<-12500000) //防止特殊情况发生
continue;
if(sum<0)
sum+=25000000;
if(hash[sum])
num+=hash[sum];
}
}
}
cout<<num<<endl;
}
return 0;
}
#include<iostream> // 1164K 1704MS
#include<cstdio>
#include<map> using namespace std; int main()
{
map<int,int>Q;
int a,b,c,d,e;
scanf("%d%d%d%d%d",&a,&b,&c,&d,&e);
Q.clear();
for(int i=-50; i<=50; i++)
{
if(!i)
continue;
for(int j=-50; j<=50; j++)
{
if(!j)
continue;
int sum=a*i*i*i+b*j*j*j;
Q[-sum]++;
}
}
int num=0;
for(int i=-50;i<=50;i++)
{
if(!i)
continue;
for(int j=-50;j<=50;j++)
{
if(!j)
continue;
for(int k=-50;k<=50;k++)
{
if(!k)
continue;
int sum=c*i*i*i+d*j*j*j+e*k*k*k;
if(Q.count(sum))
num+=Q[sum];
}
}
}
printf("%d\n",num); }
poj 1840 哈希的更多相关文章
- POJ 1840 Eps 解题报告(哈希)
a1x13+ a2x23+ a3x33+ a4x43+ a5x53=0,xi∈[-50,50],且xi!=0.让我们求所有解的可能. 首先,如果暴力判断的话,每个x的取值有100种可能,100^5肯定 ...
- POJ 1840:Eqs 哈希求解五元方程
Eqs Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 14169 Accepted: 6972 Description ...
- 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 HASH
题目链接:http://poj.org/problem?id=1840 题意:公式a1x1^3+ a2x2^3+ a3x3^3+ a4x4^3+ a5x5^3=0,现在给定a1~a5,求有多少个(x1 ...
- poj 1840 Eqs (hash)
题目:http://poj.org/problem?id=1840 题解:http://blog.csdn.net/lyy289065406/article/details/6647387 小优姐讲的 ...
- POJ 1840 Eqs 二分+map/hash
Description Consider equations having the following form: a1x13+ a2x23+ a3x33+ a4x43+ a5x53=0 The co ...
- POJ 1840 Brainman(逆序对数)
题目链接:http://poj.org/problem?id=1804 题意:给定一个序列a[],每次只允许交换相邻两个数,最少要交换多少次才能把它变成非递降序列. 思路:题目就是要求逆序对数,我们知 ...
- poj 1840(五元三次方程组)
Description Consider equations having the following form: a1x1 3+ a2x2 3+ a3x3 3+ a4x4 3+ a5x5 3=0 T ...
- POJ 1840:Eqs
Description Consider equations having the following form: a1x13+ a2x23+ a3x33+ a4x43+ a5x53= The coe ...
随机推荐
- Linux文件属性和压缩解压
目 录 第1章 Linux系统文件的属性 1 1.1 命令ls 1 1.2 inode 2 1.3 文件属性 2 1.4 env命令 2 1.5 注意: 2 第2章 ...
- CSS3--- 颜色
1.RGB是一种色彩标准,是由红(R).绿(G).蓝(B)的变化以及相互叠加来得到各式各样的颜色.RGBA是在RGB的基础上增加了控制alpha透明度的参数. 语法:color:rgba(R,G,B, ...
- 【HIHOCODER 1033 】 交错和(数位DP)
描述 输入 输入数据仅一行包含三个整数,l, r, k(0 ≤ l ≤ r ≤ 1018, |k| ≤ 100). 输出 输出一行一个整数表示结果,考虑到答案可能很大,输出结果模 109 + 7. 提 ...
- vim 系列
http://blog.csdn.net/laogaoav/article/details/17370269 非常不错
- Java基础学习总结(94)——Java线程再学习
Java线程有哪些不太为人所知的技巧与用法? 萝卜白菜各有所爱.像我就喜欢Java.学无止境,这也是我喜欢它的一个原因.日常工作中你所用到的工具,通常都有些你从来没有了解过的东西,比方说某个方法或者是 ...
- [luoguP2736] “破锣摇滚”乐队 Raucous Rockers(DP)
传送门 f[i][j]表示前i首歌放到前j个盘里最多能放多首 ntr[i][j]表示i~j中最多能放进一张盘中多少首歌 ntr数组可以贪心预处理出来. #include <cstdio> ...
- Tsinghua OJ Zuma
Description Let's play the game Zuma! There are a sequence of beads on a track at the right beginnin ...
- Codeforces Round #296 (Div. 2) C. Glass Carving [ set+multiset ]
传送门 C. Glass Carving time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- poj1330+hdu2586 LCA离线算法
整整花了一天学习了LCA,tarjan的离线算法,就切了2个题. 第一题,给一棵树,一次查询,求LCA.2DFS+并查集,利用深度优先的特点,回溯的时候U和U的子孙的LCA是U,U和U的兄弟结点的子孙 ...
- iOS 如何查看崩溃日志
参考网址: [转载]https://www.jianshu.com/p/4de55d73c82b [转载]https://blog.csdn.net/qq_26544491/article/detai ...