Eqs
Eqs
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=15029
题意:
给出系数a1,a2,a3,a4,a5,求出方程a1x1 3+ a2x2 3+ a3x3 3+ a4x4 3+ a5x5 3=0 有多少个解。
样例:
Sample Input
37 29 41 43 47
Sample Output
654 分析:
如果直接用5个for循环是会超时的,所以把方程a1x1x1x1+a2x2x2x2+a3x3x3x3+a4x4x4x4+a5x5x5x5=0
转变成-(a1x1x1x1+a2x2x2x2)=a3x3x3x3+a4x4x4x4+a5x5x5x5这样就将5层循环减少到3层循环。
#include<iostream>
#include<cstring>
#include<cmath>
using namespace std;
const int maxn=;
int i,a[],count=,sum=;
short b[maxn];
int x1,x2,x3,x4,x5;
int main()
{
memset(b,,sizeof(b));
for(i=;i<;i++)
cin>>a[i];
for(x1=-;x1<=;x1++)
{ if(x1==) continue;
for(x2=-;x2<=;x2++)
{
if(x2==) continue;
sum=-*(a[]*x1*x1*x1+a[]*x2*x2*x2);
if(sum<)
b[maxn+sum]++;
else b[sum]++;
}
}
for(x3=-;x3<=;x3++)
{
if(x3==) continue;
for(x4=-;x4<=;x4++)
{
if(x4==) continue;
for(x5=-;x5<=;x5++)
{
if(x5==) continue;
sum=a[]*x3*x3*x3+a[]*x4*x4*x4+a[]*x5*x5*x5;
if(sum<)
sum=maxn+sum;
count=count+b[sum];
} }
}
cout<<count<<endl;
return ;
}
Eqs的更多相关文章
- POJ 1840 Eqs
Eqs Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 15010 Accepted: 7366 Description ...
- 【POJ】1840:Eqs【哈希表】
Eqs Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 18299 Accepted: 8933 Description ...
- 測试赛C - Eqs(哈希)
C - Eqs Time Limit:5000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit Stat ...
- poj 1840 Eqs 【解五元方程+分治+枚举打表+二分查找所有key 】
Eqs Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 13955 Accepted: 6851 Description ...
- 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: 14169 Accepted: 6972 Description ...
- POJ1840 Eqs
题意描述 Eqs 求一个五元方程 \(a_1x_1^3+a_2x_2^3+a_3x_3^3+a_4x_4^3+a_5x_5^3=0\) 的解的个数. 题中给出 \(a_i\) 的值并且保证 \(-50 ...
- POJ 1840 Eqs 二分+map/hash
Description Consider equations having the following form: a1x13+ a2x23+ a3x33+ a4x43+ a5x53=0 The co ...
- POJ 1840 Eqs 暴力
Description Consider equations having the following form: a1x13+ a2x23+ a3x33+ a4x43+ a5x53=0 The ...
随机推荐
- hdu 4045 2011北京赛区网络赛F 组合数+斯特林数 ***
插板法基础知识 斯特林数见百科 #include<iostream> #include<cmath> #include<cstdio> #include<cs ...
- URAL 1966 Cycling Roads 点在线段上、线段是否相交、并查集
F - Cycling Roads Description When Vova was in Shenzhen, he rented a bike and spent most of the ...
- 【rqnoj39】 饮食问题
题目描述 Bessie 正在减肥,所以她规定每天不能吃超过 C (10 <= C <= 35,000)卡路里的食物.农民 John 在戏弄她,在她面前放了B (1 <= B < ...
- Laravel错误与日志处理
App\Exceptions\Handler class is where all exceptions triggered by your application are logged and th ...
- [xsd学习]xsd元素限定
限定(restriction)用于为 XML 元素或者属性定义可接受的值 一.xsd中主要限定格式如下: <xs:element name="xxx"><!--元 ...
- Kafka 分布式消息队列介绍
Kafka 分布式消息队列 类似产品有JBoss.MQ 一.由Linkedln 开源,使用scala开发,有如下几个特点: (1)高吞吐 (2)分布式 (3)支持多语言客户端 (C++.Java) 二 ...
- three.js运动
<!DOCTYPE html> <html> <head> <title>Example 01.04 - Materials, light and an ...
- 每天一个linux命令---telnet
执行telnet指令开启终端机阶段作业,并登入远端主机. telnet的命令的格式: telnet ip port 例1: 建立连接不成功 [richmail@portal bin]$ telne ...
- 使用Jaxb2进行xml与bean的转义时Date的format设置
参考http://jackyrong.iteye.com/blog/1826699 JAXB转换JAVA OBJECT到XML的时候,对java.util.Date的转换有些要注意的地方 输出的格式为 ...
- BZOJ 2626 & KDtree
题意: 二维平面n个点 每次给出一个点询问距离第k小的点. SOL: kdtree裸题,抄了一发别人的模板...二维割起来还是非常显然的.膜rzz的论文. 不多说了吧.... Code: /*==== ...