Poj 1840 Eqs(哈兮+复杂度)
来源:互联网 发布:chrome插件位置 mac 编辑:程序博客网 时间:2024/06/05 05:40
Eqs
Time Limit: 5000MS Memory Limit: 65536KTotal Submissions: 14031 Accepted: 6893
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.
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
数据范围有点大不能用5个for来循环,1m中程序可执行1000次,5个for()为10e,而此题目的上限是5000*1000.
对于此种题目一般是对公式做变形。
,做一个ha[]表来进行映射,先枚举左边的公式,放进哈兮表,然后在枚举右边看是否在ha【】表里。
时间复杂度为n^3(n^2+n^3).
<pre name="code" class="cpp">#include<iostream>#include<cstring>#include<cstdio>using namespace std;short ha[25000001];//为了避免MLE,用short定义,因为数据范围最大为50^4*2,因为等号右边,有个三项相加的所以至少开到大于他。数组小会有Windowsint main(){ int s; int a1,a2,a3,a4,a5; while(scanf("%d%d%d%d%d",&a1,&a2,&a3,&a4,&a5)!=EOF) { memset(ha,0,sizeof(ha)); for(int i=-50;i<=50;i++)//一定注意不能让i=0,不可以写成for(i=-50;i<=50&&i!=0;i++)如果i==0,循环便中止 { if(0==i) continue; for(int j=-50;j<=50;j++) { if(0==j) continue; s=a1*i*i*i+a2*j*j*j; s*=(-1); if(s<0) s+=25000000; ha[s]++; } } int ans=0; for(int x=-50;x<=50;x++) { if(0==x) continue; for(int y=-50;y<=50;y++) { if(y==0) continue; for(int z=-50;z<=50;z++) { if(0==z) continue; s=a3*x*x*x+a4*y*y*y+a5*z*z*z; if(s<0)//每次复值都要判断s符号,因为下标不能为-,要不处理且s<0会有Windows s+=25000000; if(ha[s]) ans+=ha[s]; } } } printf("%d\n",ans); } return 0;}
0 0
- Poj 1840 Eqs(哈兮+复杂度)
- poj 1840 Eqs
- POJ 1840 Eqs
- poj 1840 Eqs
- POJ 1840 Eqs
- POJ 1840 Eqs hash
- POJ-1840 Eqs【Hash】
- poj 1840 Eqs 【hash】
- POJ 1840 Eqs
- poj-1840 Eqs
- POJ 1840 Eqs
- POJ 1840 Eqs
- poj 1840 Eqs
- POJ 1840 Eqs
- POJ 1840 Eqs
- POJ 1840(Eqs)
- POJ 1840 Eqs
- POJ 1840 Eqs
- 2014-2015年工作学习记录
- HDOJ-2002-计算球体积
- 2102 A计划【bfs】
- const 总结
- 常去的一些外国网站
- Poj 1840 Eqs(哈兮+复杂度)
- oracle存储过程
- tomcat服务器不写端口号、不写项目名访问项目、虚拟目录配置
- TestNG监听器实现失败自动截图、重跑、自定义html结果文件功能
- POJ3264Balanced Lineup【RMQ模板】
- Ubuntu挂载新硬盘 && ubuntu备份和重装 && minicom抓串口信息 && ubuntu比较工具
- Hdoj 2094 产生冠军排序(暴力即过)
- ListView中包含Button时候,怎么获取listView的onItemClick事件,2015-8-10
- 素数问题