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
Sample Output
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, ...
随机推荐
- 弱类型变量原理探究(转载 http://www.csdn.net/article/2014-09-15/2821685-exploring-of-the-php)
N首页> 云计算 [问底]王帅:深入PHP内核(一)——弱类型变量原理探究 发表于2014-09-19 09:00| 13055次阅读| 来源CSDN| 36 条评论| 作者王帅 问底PHP王帅 ...
- MVC4中下拉菜单和单选框的简单设计方法
举例一: @Html.LabelFor(model => model.Gender) @Html.DropDownListFor(model => model.Gender, new[] ...
- 夺命雷公狗ThinkPHP项目之----企业网站28之网站前台左侧导航的实现
我们基于刚才在model层的找顶级分类的代码在进行修改即可: <?php namespace Home\Controller; use Think\Controller; class Commo ...
- Linux(CentOS) 如何查看当前占用CPU或内存最多的K个进程
一.可以使用以下命令查使用内存最多的K个进程 方法1: ps -aux | sort -k4nr | head -K 如果是10个进程,K=10,如果是最高的三个,K=3 说明:ps -aux中(a指 ...
- PL/SQL编程基础
范例:编写不做任何工作的PL/SQL块 BEGIN NULL ; END ; / 范例:编写一个简单的PL/SQL程序 DECLARE v_num NUMBER ; -- 定义一个变量v_num ...
- T-sql语句中GO的作用及语法【转】
1. 作用: 向 SQL Server 实用工具发出一批 Transact-SQL 语句结束的信号.2. 语法:一批 Transact-SQL 语句GO如Select 1Select 2Select ...
- Awk使用一例:获取ASCII可见字符
要做一个需求, 支持可见特殊字符的密码设置. 首先, 需要获取到所有可见特殊字符. 到网上搜索到 ASCII 字符表格, 并复制到文本文件 vschars.txt: 00 00 0 nul 100 4 ...
- linux下xargs命令用法详解 【转】
转自:http://blog.chinaunix.net/uid-128922-id-289992.html xargs在linux中是个很有用的命令,它经常和其他命令组合起来使用,非常的灵活. xa ...
- 使用Jconsole监控weblogic的配置方法
在项目中发现full gc非常频繁.达到了每分钟13次.我怀疑可能会有内存泄露.于是在晚上找了内存泄露的资料. 内存长期占用并导致系统不稳定一般有两种可能: 1. 对象被大量创建而且被缓存,在旧的对象 ...
- Length of Last Word
class Solution { public: int lengthOfLastWord(string s) { ; ; while(s[i]&&s[i]==' ') i++; // ...