POJ 1840 Eqs 暴力
Description Consider equations having the following form:
a1x13+ a2x23+ a3x33+ a4x43+ a5x53=0 The coefficients are given integers from the interval [-50,50]. It is consider a solution a system (x1, x2, x3, x4, x5) that verifies the equation, xi∈[-50,50], xi != 0, any i∈{1,2,3,4,5}. Determine how many solutions satisfy the given equation. Input The only line of input contains the 5 coefficients a1, a2, a3, a4, a5, separated by blanks.
Output The output will contain on the first line the number of the solutions for the given equation.
Sample Input 37 29 41 43 47 Sample Output 654 Source Romania OI 2002
|
题目大意:给a1, a2, a3, a4, a5,5个数且 xi∈[-50,50],xi != 0, any i∈{1,2,3,4,5}.求出有多少种解使得a1x13+ a2x23+ a3x33+ a4x43+ a5x53=0
题解:5个for肯定会超时(1e8),可以分开考虑,移项可以得到-a1x13- a2x23= a3x33+ a4x43+ a5x53,把左边所有的可能存在数组里,右边查询即可,左边可能为负数,所以两边同时加上25001000
#include <stdio.h>
char mp[];
int main()
{
int t,i, j, k,a2, a1, a3,a4,a5;
scanf("%d%d%d%d%d", &a1, &a2, &a3, &a4, &a5);
for(j=-;j<=;j++)
for(k=-;k<=;k++)
if(j!=&&k!=)
mp[a1*j*j*j+a2*k*k*k+]++;
for(t=,i=-;i<=;i++)
for(j=-;j<=;j++)
for(k=-;k<=;k++)
if(i!=&&j!=&&k!=)
t += mp[-a3*k*k*k-i*i*i*a4-j*j*j*a5];
printf("%d\n", t);
return ;
}
POJ 1840 Eqs 暴力的更多相关文章
- poj 1840 Eqs (hash)
题目:http://poj.org/problem?id=1840 题解:http://blog.csdn.net/lyy289065406/article/details/6647387 小优姐讲的 ...
- 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 ...
- POJ 1840 Eqs 二分+map/hash
Description Consider equations having the following form: a1x13+ a2x23+ a3x33+ a4x43+ a5x53=0 The co ...
- POJ 1840 Eqs(乱搞)题解
思路:这题好像以前有类似的讲过,我们把等式移一下,变成 -(a1*x1^3 + a2*x2^3)== a3*x3^3 + a4*x4^3 + a5*x5^3,那么我们只要先预处理求出左边的答案,然后再 ...
- 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 暴力+标记
Description Consider equations having the following form: a1x1 3+ a2x2 3+ a3x3 3+ a4x4 3+ a5x5 3=0 T ...
- 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, ...
随机推荐
- 转:装完Centos7提示Initial setup of CentOS Linux 7 (core)
在用U盘装完CentOS后,重新开机启动后显示: Initial setup of CentOS Linux 7 (core) 1) [x] Creat user 2) [!] License inf ...
- c#经典俄罗斯方块 vs2012开发
把网上两个开源的俄罗斯方块,整合到一起了,开发环境vs2012+.net 4.0,有问题.建议可以加群沟通哦 复古的 c#写的一个俄罗斯方块小游戏,友好的人机交互,具体功能如下: 1.游戏分七个关卡, ...
- MVC4 导出word
添加程序包 DocX using System.IO;using Novacode; /// <summary> /// 导出Word /// </summary> publi ...
- 【ipython技巧】使用shell命令
在ipython终端时,可能临时需要使用shell命令进行简单处理: 可以在shell命令前面使用 !(感叹号) 比如在win7,ipython下想要使用sublime新建一个py,可以这样 !sub ...
- 形状特征提取-Hu不变矩(转载)
[原文部分转载]:http://blog.csdn.net/wrj19860202/archive/2011/04/16/6327094.aspx 在连续情况下,图像函数为 ,那么图像的p+q阶几何矩 ...
- 【python cookbook】【数据结构与算法】10.从序列中移除重复项且保持元素间顺序不变
问题:从序列中移除重复的元素,但仍然保持剩下的元素顺序不变 解决方案: 1.如果序列中的值时可哈希(hashable)的,可以通过使用集合和生成器解决.
- Web SQL
HTML5本地存储——Web SQL Database 基于 HTML5 中的 Web SQL Database 来构建应用程序 前端HTML5几种存储方式的总结 <!DOCTYPE HTML& ...
- SQLServer学习笔记<> 表连接查询----交叉连接、内连接、左连接、右连接
(1)交叉连接(cross join)即我们所说的笛卡尔积.查询出满足两张表所有的记录数,A(3条记录),B(9条记录),A*B(27条记录). 比如:雇员表(HR.employees)和货运公司(S ...
- C# 插件
1.EsFrameWork框架 http://www.oraycn.com/ESFramework_download.aspx
- [转] Xcode4.4.1下安装高德地图详细教程
转载地址:http://blog.csdn.net/mad1989/article/details/7913404 此教程和官方的没有太大区别,省略了好多没用的步骤,添加framework的方式是最新 ...