震惊!map的常数居然如此之大

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

题目大意

给出一个五元三次方程的系数,求满足xi∈[-50,50]的方程根组数。

题目分析

算是一道比较经典也挺简单的meet in middle吧。

五个根都拿来枚举?$100^5$飞到天上去……

那么算出来前四个,就可以得到第五个根,再判断一下是否合法?$100^4$照样很悬。

从传统算法再延伸一下就可以得到meet in middle的核心思想:将所要解决的问题转化成$left=right$的形式,其中$left$和$right$的计算复杂度最好均匀一些(不过视情况而定,毕竟有些题时限很紧但是内存N/A)。我们保存所有left的信息,再枚举所有right比对是否匹配得上。这样一般来说,复杂度能从$O(n^k)$降为$O(n^\frac{k}{2})$。

话说map为什么这么慢!

 #include<cstdio>
#include<map> short f[];
int a1,a2,a3,a4,a5,ans,t,g[]; int main()
{
scanf("%d%d%d%d%d",&a1,&a2,&a3,&a4,&a5);
for (int i=-; i<=; i++)
g[i+] = i*i*i;
for (int x=-; x<=; x++)
if (x)
for (int y=-; y<=; y++)
if (y){
t = -a1*g[x+]-a2*g[y+];
if (t < ) t += ;
f[t]++;
}
for (int x=-; x<=; x++)
if (x)
for (int y=-; y<=; y++)
if (y)
for (int z=-; z<=; z++)
if (z){
t = a3*g[x+]+a4*g[y+]+a5*g[z+];
if (t < ) t += ;
ans += f[t];
}
printf("%d\n",ans);
return ;
}

END

最新文章

  1. SQL Server-聚焦强制索引查询条件和Columnstore Index(九)
  2. 前端性能优化--为什么DOM操作慢?
  3. jquery中attr()与prop()区别
  4. 在XML drawable中引用自定义颜色
  5. js中Array自定义contains, indexOf, delete方法.
  6. iOS Architecture
  7. Linux Shell脚本入门:tee命令
  8. OC加强-day05
  9. 介绍TableView非常不错的一篇文章
  10. ps使用方法续
  11. iOS开发之 用第三方类库实现ScrollView
  12. POJ - 3414 bfs [kuangbin带你飞]专题一
  13. 【建模+强连通分量】POJ1904 King&#39;s Quest
  14. css遮罩蒙版效果 分栏效果
  15. spring cloud_1_mm_ribbon
  16. Android内存优化(一)Dalvik虚拟机和ART虚拟机对比
  17. 如何删除自己上传的CSDN资源(亲测有效)
  18. Codeforces 937D - Sleepy Game
  19. python Django 项目创建
  20. SQL中varchar和nvarchar有什么区别

热门文章

  1. Spring事件机制详解
  2. python之文件路径截取 &amp; endswith()
  3. IMG 的alt和title的区别(转自 百度空间--路云的世界)
  4. 1-28Map简介
  5. 转 Oracle Cluster Health Monitor(CHM)简介
  6. JAVA常用知识总结(十三)——数据库(三)
  7. 100 Same Tree 相同的树
  8. python学习之模块:
  9. [转]Hibernate对象的三种状态
  10. php调用c# webservice方法