POJ1840Eps
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的更多相关文章
随机推荐
- jQuery 实现网页图片动态游走,碰到边框反弹
学学jQuery,实现个小功能练练手 需要用到定时器 html代码如下 <html> <head> <title></title> <script ...
- c#多层嵌套Json
Newtonsoft.Json.Net20.dll 下载请访问http://files.cnblogs.com/hualei/Newtonsoft.Json.Net20.rar 在.net 2.0中提 ...
- C# WinForm设置TreeView选中节点
这里假定只有两级节点,多级方法类似.遍历节点,根据选中节点文本找到要选中的节点.treeView.SelectedNode = selectNode; /// <summary> /// ...
- ASP.NET MVC 2 验证
来源:http://www.cnblogs.com/jhxk/articles/2612885.html 只为把自己觉的好的存起来 对用户输入的验证以及强制业务规则/逻辑是大多数web应用的核心需求 ...
- Docker 启动失败Starting docker (via systemctl): Job for docker.service failed
Starting docker (via systemctl): Job for docker.service failed. See 'systemctl status docker.servic ...
- Oracle 表的连接方式(1)-----Nested loop join和 Sort merge join
关系数据库技术的精髓就是通过关系表进行规范化的数据存储,并通过各种表连接技术和各种类型的索引技术来进行信息的检索和处理. 表的三种关联方式: nested loop:从A表抽一条记录,遍历B表查找匹配 ...
- 相同的 birthday
Description Sometimes some mathematical results are hard to believe. One of the common problems is t ...
- mac升级yosemite后安装gd的freetype扩展
Mac升级系统到 Yosemite 10.10,对于各位Coder来说,还是需要一些时间来折腾的! @星空之下 同学反映 PHPCMS 的验证码图片不能正常显示,反馈该验证码需要GD库支持FreeTy ...
- iTween基础之Rotate(旋转角度)
一.基础介绍:二.基础属性 原文地址 :http://blog.csdn.net/dingkun520wy/article/details/50696489 一.基础介绍 RotateTo:旋转游戏物 ...
- Configure xterm Fonts and Colors for Your Eyeball
https://wiki.mpich.org/mpich/index.php/Configure_xterm_Fonts_and_Colors_for_Your_Eyeball Screenshot ...