POJ 1840 HASH
题目链接:http://poj.org/problem?id=1840
题意:公式a1x1^3+ a2x2^3+ a3x3^3+ a4x4^3+ a5x5^3=0,现在给定a1~a5,求有多少个(x1~x5)的组合使得公式成立。并且(x1~x5)取值再[-50,50]且不能为0
思路:因为x的值范围比较小,只有100.所以可以先求出 a1x1^3+a2x2^3+a3x3^3. 然后在求 (-1)*(a4x4^3+a5x5^3)从前面的所得的Hash表进行二分查找。
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<time.h>
#include<map>
using namespace std;
typedef long long int LL;
const int MAXN=+;//100^3
int a,b,c,d,e;
int Hash[MAXN];
int main(){
#ifdef kirito
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
int start=clock();
while(~scanf("%d%d%d%d%d",&a,&b,&c,&d,&e)){
int cnt=,ans=;
for(int i=-;i<=;i++){ //make a1x1^3+a2x2^3+a3x3^3
if(i==){continue;}
for(int j=-;j<=;j++){
if(j==){continue;}
for(int k=-;k<=;k++){
if(k==){continue;}
int Sum=a*i*i*i+b*j*j*j+c*k*k*k;
Hash[cnt++]=Sum;
}
}
}
sort(Hash,Hash+cnt); //sorted
for(int i=-;i<=;i++){ //make (-1)*(a4x4^3+a5x5^3)
if(i==){continue;};
for(int j=-;j<=;j++){
if(j==){continue;}
int Sum=(-)*(d*i*i*i+e*j*j*j);//the search number
for(int k=lower_bound(Hash,Hash+cnt,Sum)-Hash;k<cnt;k++){//binary search the number
if(Hash[k]!=Sum){
break;
}
else{
ans++;
}
}
}
}
printf("%d\n",ans);
}
#ifdef LOCAL_TIME
cout << "[Finished in " << clock() - start << " ms]" << endl;
#endif
return ;
}
POJ 1840 HASH的更多相关文章
- 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, ...
- 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 3274 HASH
题目链接:http://poj.org/problem?id=3274 题意+思路: 点击这里 补充:因为有减法运算,所以可能会造成运算后结果为负数,所以需要把结果统一转换成正数[不然数组下标访问不到 ...
- POJ 3349 HASH
题目链接:http://poj.org/problem?id=3349 题意:你可能听说话世界上没有两片相同的雪花,我们定义一个雪花有6个瓣,如果存在有2个雪花相同[雪花是环形的,所以相同可以是旋转过 ...
- POJ 2785 HASH
题目链接:http://poj.org/problem?id=2785 题意:给定n行数字,每行4个数分别是a,b,c,d,现在要求能有多少个(a,b,c,d)组合并且和为0 思路:n^2统计所有(a ...
- 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 ...
随机推荐
- jQuery中attr()方法用法实例
本文实例讲述了jQuery中attr()方法用法.分享给大家供大家参考.具体分析如下: 此方法设置或返回匹配元素的属性值. attr()方法根据参数的不同,功能也不同. 语法结构一: 获取第一个匹配元 ...
- Spring+SpringMVC+Mybatis 多数据源整合(转)
转载自:http://blog.csdn.net/q908555281/article/details/50316137 目录(?)[-]拷贝所需jar拷贝jar文件需要的jar文件入下图所示因为我的 ...
- spring mvc配置完后实现下载功能
实现是前台: <%@ page language="java" contentType="text/html; charset=UTF-8" pageEn ...
- JQuery页面加载
第一种: $(document).ready(function(){ alert("第一种方法."); }); 第二种: $(function(){ alert("第二种 ...
- LeetCode 326 Power of Three
Problem: Given an integer, write a function to determine if it is a power of three. Could you do it ...
- NEFU 1112 粉刷栅栏算法
题目链接 中文题 简单搜索题 例数据 输入 6 1 1 1 1 9 9 输出 3 注意是每一个递归搜索都返回一个min 而不是只有总的返回min #include <cstdio> #in ...
- oracle 监控
sqlplus "/as sysdba" .监控当前数据库谁在运行什么SQL语句 SELECT osuser, username, sql_text from v$session ...
- C#冒泡排序
C#最简单的冒泡排序,需要的朋友可作参考: 思路: 使用两个for循环,就可以遍历数组,这样就可以确保每个数组元素都被使用 对比前后两个数,将小的数字和大的交换位置,引入一个临时变量temp来进行交换 ...
- C++ 类的静态成员及静态成员函数
对象与对象之间的成员变量是相互独立的.要想共用数据,则需要使用静态成员和静态方法. 只要在类中声明静态成员变量,即使不定义对象,也可以为静态成员变量分配空间,进而可以使用静态成员变量.(因为静态成员变 ...
- Hadoop-2.X HA模式下的FSImage和EditsLog合并过程
补充了一下NameNode启动过程中有关FSImage与EditsLog的相关知识. 一.什么是FSImage和EditsLog 我们知道HDFS是一个分布式文件存储系统,文件分布式存储在多个Data ...