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的更多相关文章
随机推荐
- nginx配置多个网址
实战Nginx与PHP(FastCGI)的安装.配置与优化:http://ixdba.blog.51cto.com/2895551/806622 Nginx配置文件详细说明:http://www.cn ...
- wordpress 在linux上配置固定url方法
wordpress 设置固定url总结 相信好多用wordpress的网友为了提升wordpress对搜索引擎的友好,或者是为了写的博客地址更好记,都会在wordpress的后台设置固定url的方式. ...
- mysql 让一个存储过程定时作业的代码
1.在mysql 中建立一个数据库 test1 语句:create database test1 2.创建表examinfo create table examinfo( id int auto_in ...
- 22 高级SQL特性
1.约束 为正确地进行关系数据库设计,需要一种方法来保证只在表中插入合法的数据.例如,如果Orders表存储订单信息,OrderItems表存储订单详细内容,应该保证Orderitems中引用的任何订 ...
- grappelli美化django的admin页面
开始用admin时候,觉得它的页面实在...宁愿自己写modules,多费点时间 grappelli可以把admin变得非常美观,配置起来也很简单 第一步,先下载grappelli,搜索一下,wind ...
- js中ajax异步导致的一些问题
问题1:ajax默认是异步,所以在ajax中对外面定义的变量赋值,不能正确赋值 $("form").submit( var flag; $.ajax({ type: 'GET', ...
- 【转载】Powershell获取世纪互联Office365中所有用户的OWA时区
get-mailbox -resultsize unlimited | Get-MailboxRegionalConfiguration | select Identity,TimeZone | wh ...
- Python - python不是内部或外部命令
[方法一]我的电脑->属性->高级->环境变量->系统变量 在系统变量里找到PATH,双击PATH,在结尾加上 ";C:\Python26"(不要引号) ...
- Notes of the scrum meeting(2013/10/27)
软工项目组buaa_smile确定自由项目主题及实现功能的scrum meeting meeting time:1:00~2:00p.m.,October 27th,2013 meeting plac ...
- iOS刷新第三方MJRefresh的基本使用
iOS开发中最好用的刷新第三方框架 MJRefresh GitHub : https://github.com/CoderMJLee/MJRefresh UIRefreshControl的介绍 1,U ...