http://poj.org/problem?id=1840

题意 : 有这样一个式子a1x13+ a2x23+ a3x33+ a4x43+ a5x53=0,给你五个系数的值,让你找出x1,x2,x3,x4,x5的值满足这个式子,满足这个式子的方案有多少种输出

思路 : 这个题的话我一开始想的就是暴搜,五个for循环,但肯定会超时啊,问了会神才知道,原来这个题变通一下就行了,既然五个for循环超时那就分开,两个和三个,a1x13+ a2x23+ a3x33= -(a4x43+ a5x53),这样去搜就可以了,哈希表存一下,还有,这个的话,若x4和x5系数和x都是50,那么50*50*50*50+50*50*50*50就等于1250万,再加上负数,所以数组就要开到2500万,用int就会超内存,唉,多么痛的领悟啊!我交了两遍呢,所以用short定义

#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std ;
const int maxn = ;
short ch[maxn] ;
int main()
{
int a,b,c,d,e ;
scanf("%d %d %d %d %d",&a,&b,&c,&d,&e);
int sum = ;
memset(ch,,sizeof(ch));
for(int x1 = - ; x1 <= ; x1++)
{
if( x1 == )
continue ;
for(int x2 = - ; x2 <= ; x2++)
{
if(x2 == )
continue ;
for(int x3 = - ; x3 <= ; x3++)
{
if(x3 == )
continue ;
sum = a*x1*x1*x1+b*x2*x2*x2+c*x3*x3*x3 ;
if(sum < )
sum += maxn ;
ch[sum] ++ ;
}
}
}
int count = ;
for(int x4 = - ; x4 <= ; x4++)
{
if(x4 == )
continue ;
for(int x5 = - ; x5 <= ; x5++)
{
if(x5 == )
continue ;
sum = d*x4*x4*x4+e*x5*x5*x5 ;
if(sum < )
sum += maxn ;
count += ch[sum] ;
}
}
printf("%d\n",count) ;
return ;
}
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
#define MAXN 25000001
using namespace std;
int main()
{
int a1,a2,a3,a4,a5;
scanf("%d%d%d%d%d",&a1,&a2,&a3,&a4,&a5);
map<int,int>q;
for(int x1=-; x1<=; x1++)
{
if(!x1) continue;
for(int x2=-; x2<=; x2++)
{
if(!x2) continue;
int sum=a1*x1*x1*x1+a2*x2*x2*x2;
if(q.find(sum)==q.end())
q.insert(pair<int,int>(sum,));
else q[sum]++;
}
}
int ans=;
for(int x3=-; x3<=; x3++)
{
if(!x3) continue;
for(int x4=-; x4<=; x4++)
{
if(!x4) continue;
for(int x5=-; x5<=; x5++)
{
if(!x5) continue;
int sum=a3*x3*x3*x3+a4*x4*x4*x4+a5*x5*x5*x5;
if(q.find(sum)==q.end()) continue;
ans+=q[-sum];
}
}
}
printf("%d\n",ans);
return ;
}

下面这个是会神用map写的

POJ1840Eps的更多相关文章

随机推荐

  1. 求一个String 类型数组是不是都是回文,是返回1,否则返回-1

    package 回文; public class yhisHuiWen { public static void ishuiwen(String arr[]){ boolean flag=true;/ ...

  2. Linux时间相关函数

    相关文件: /etc/localtime  本地时间二级制文件 /etc/sysconfig/clock  时区配置文件 /usr/share/zoneinfo  存储各个时区的二进制文件 时间修改方 ...

  3. oracle创建用户,修改用户,删除用户等关于用户的

    --直接修改底层表 USER$ 更换用户名 1.windows 平台下运行 cmd 2.sqlplus /nolog 3.SQL> conn SYSTEM/123@ORCL as sysdba ...

  4. 查看leapmotion的frame信息

    leapmotion的SDK里有个c#实例,很详细,其中的frame类已经把这些封装的很完善了.可惜是控制台的,运行时很难去找那些动作对应的哪些数据.我今天做的就是把它们在窗体控件里分别显示出来,这样 ...

  5. 连续子数组的最大和/1007. Maximum Subsequence Sum (25)

    题目描述 HZ偶尔会拿些专业问题来忽悠那些非计算机专业的同学.今天测试组开完会后,他又发话了:在古老的一维模式识别中,常常需要计算连续子向量的最大和,当向量全为正数的时候,问题很好解决.但是,如果向量 ...

  6. getchar(),gets(),scanf()的差异比较

    scanf( )函数和gets( )函数都可用于输入字符串,但在功能上有区别.若想从键盘上输入字符串"hi hello",则应该使用gets()函数. gets可以接收空格:而sc ...

  7. Visual Studio

    1.必备神器http://www.cnblogs.com/stoneniqiu/p/3488546.html 2.常用快捷键http://www.cnblogs.com/TankXiao/p/3468 ...

  8. 编译linux内核问题

    1: openssl/opensslv.h: No such file or directory sudo apt-get install libssl-dev 2:一般配置内核树,需要先make o ...

  9. KAFKA分布式消息系统

    2015-01-05 大数据平台 Hadoop大数据平台 基本概念 kafka的工作方式和其他MQ基本相同,只是在一些名词命名上有些不同.为了更好的讨论,这里对这些名词做简单解释.通过这些解释应该可以 ...

  10. JAVA类与对象(三)----类定义关键字详解

    static 表示静态,它可以修饰属性,方法和代码块. 1.static修饰属性(类变量),那么这个属性就可以用类名.属性名来访问,也就是使这个属性成为本类的类变量,为本类对象所共有.这个属性就是全类 ...