Eqs - poj 1840(hash)
题意:对于方程:a1x13+ a2x23+ a3x33+ a4x43+ a5x53=0 ,有xi∈[-50,50], xi != 0, any i∈{1,2,3,4,5}. 现在给出a1,a2,a3,a4,a5的值,求出满足上面方程的解有多少个。
思路:hash的应用。暴力枚举的话会达到100^5,明显会超时。所以将方程分成-(a1x13+ a2x23 )和 a3x33+a4x43+ a5x53 两部分,若这两部分相等,则为方程的一个解。
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
short hash[];
int main(){
int coff[],base[];
int i,j,k;
int result=;
for(i=;i<;i++){
scanf("%d",&coff[i]);
}
for(i=-;i<=;i++){
int tmp=i*i*i;
base[i+]=tmp;
}
memset(hash,,sizeof(hash));
for(i=-;i<=;i++){
for(j=-;j<=;j++){ if(i!=&&j!=){
int tmp=coff[]*base[i+]+coff[]*base[j+];
hash[tmp+]++;
}
}
} for(i=-;i<=;i++){
for( j=-;j<=;j++){
for(k=-;k<=;k++){
if(i!=&&j!=&&k!=){
int tmp=coff[]*base[i+]+coff[]*base[j+]+coff[]*base[k+];
tmp=-tmp;
if(tmp<&&tmp>=-)
result+=hash[tmp+];
} } }
}
printf("%d\n",result);
return ;
}
附:
| Time Limit: 5000MS | Memory Limit: 65536K | |
| Total Submissions: 14021 | Accepted: 6889 |
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
Eqs - poj 1840(hash)的更多相关文章
- 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 Eqs(hash)
题意 输入a1,a2,a3,a4,a5 求有多少种不同的x1,x2,x3,x4,x5序列使得等式成立 a,x取值在-50到50之间 直接暴力的话肯定会超时的 100的五次方 10e了都 ...
- POJ 1840 Eqs
Eqs Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 15010 Accepted: 7366 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 Eqs(乱搞)题解
思路:这题好像以前有类似的讲过,我们把等式移一下,变成 -(a1*x1^3 + a2*x2^3)== a3*x3^3 + a4*x4^3 + a5*x5^3,那么我们只要先预处理求出左边的答案,然后再 ...
- poj 1840 Eqs 【解五元方程+分治+枚举打表+二分查找所有key 】
Eqs Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 13955 Accepted: 6851 Description ...
- POJ 1840:Eqs
Description Consider equations having the following form: a1x13+ a2x23+ a3x33+ a4x43+ a5x53= The coe ...
随机推荐
- 【云计算】使用nsenter进入Docker容器进行调试
[nsenter安装使用] cd /tmp curl https://www.kernel.org/pub/linux/utils/util-linux/v2.24/util-linux-2.24.t ...
- Spark 开发环境搭建
原文见 http://xiguada.org/spark-develop/ 本文基于Spark 0.9.0,由于它基于Scala 2.10,因此必须安装Scala 2.10,否则将无法运行Spar ...
- 转: 学ppt的网址与素材
转:http://www.jianshu.com/p/89b261e0b8f6 你说你要学ppt,可你知道这些吗? 之前身边的同学总说做PPT很难,每次做ppt都头疼,我都对此很不屑,直到前一段开 ...
- Win7文件正在使用无法删除怎么办
Windows 7下删除文件提示被占用?系统内置工具搞定 Windows7之家(www.win7china.com):Windows7下删除文件提示被占用?系统内置工具搞定 在Windows中,删除文 ...
- SQL如何将EXCEL导入到SQL数据库
1 新建一个EXCEL工作表,注意默认有三个工作簿,我们只在Sheet1中创建几个字段并存储若干值保存为TEST.xls 2运行Excel to MySQL软件,注意Sourece和Destinati ...
- Core Data 删除某条指定记录的数据
一:操作流程 先查询得到某条要删除的数据 然后删除某记录 二:演示代码 //删除 - (void)deleteThePersonData { NSFetchRequest *fetchRequest ...
- mui ajax方法
mui ajax方法详解: mui提供了mui.ajax,在此基础上有分装出mui.get()/mui.getJSON()/mui.post()三个方法. mui.ajax( url [,settin ...
- input text 去掉标签下拉提示autocomplete
autocomplete 属性 autocomplete 属性规定输入字段是否应该启用自动完成功能. 自动完成允许浏览器预测对字段的输入.当用户在字段开始键入时,浏览器基于之前键入过的值,应该显示出在 ...
- Ffmpeg 视频教程 向视频中添加文字
Ffmpeg支持添加文字功能,具体如何将文字叠加到视频中的每一张图片,FFmpeg调用了文字库FreeSerif.ttf.当我们 用到ffmpeg 添加文字功能时 我们需要先下载改文字库,下载地址是h ...
- SSL and SSL Certificates Explained
Secure Sockets Layer (SSL) and Transport Layer security (TLS ) are protocols that provide secure com ...