C - Eqs

Time Limit:5000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

Submit Status

Description

Consider equations having the following form: 

a1x1 3+ a2x2 3+ a3x3 3+ a4x4 3+ a5x5 3=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
哈希存下一開始的两个值,看找后面三个的和,看能不能出现0
让5个for循环转化为1个双重for循环+1个三重for循环

#include <cstdio>
#include <cstring>
#include <algorithm>
#define maxint 25000000
using namespace std;
short p[25000001];
int main()
{
int a, b, c, d, e, i, j, k, n, s;
while(scanf("%d %d %d %d %d", &a, &b, &c, &d, &e)!=EOF)
{
s = 0;
memset(p,0,sizeof(p));
for(i = -50; i <= 50 ; i++)
{
if(!i)
continue ;
for(j=-50; j<=50; j++)
{
if(!j)
continue ;
n = i*i*i*a + j*j*j*b ;
n = -n ;
if(n<0)
n += maxint ;
p[n]++;
}
}
for(i = -50 ; i <= 50; i++)
{
if(!i)
continue ;
for(j = -50; j <= 50; j++)
{
if(!j)
continue ;
for(k = -50; k <= 50; k++)
{
if(!k)
continue ;
n= i*i*i*c + j*j*j*d + k*k*k*e;
if(n < 0)
n += maxint ;
if(p[n])
s += p[n];
}
}
}
printf("%d\n",s);
}
return 0;
}

測试赛C - Eqs(哈希)的更多相关文章

  1. SDUT2013级測试赛_D

    题目描写叙述 给出一棵含有n个点的树.每一个点权值为wi.求从根节点到叶子结点权值和最大的那条路经的权值和是多少. 输入 n(1<= n && n <= 10000). 接 ...

  2. 測试赛D - The War(有控制范围的贪心)

    D - The War Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu Submit St ...

  3. 一致性哈希算法(consistent hashing)样例+測试。

    一个简单的consistent hashing的样例,非常easy理解. 首先有一个设备类,定义了机器名和ip: public class Cache { public String name; pu ...

  4. atitit.jndi的架构与原理以及资源配置and单元測试实践

    atitit.jndi的架构与原理以及资源配置and单元測试实践 1. jndi架构 1 2. jndi实现原理 3 3. jndi资源配置 3 3.1. resin  <database> ...

  5. Window平台搭建Redis分布式缓存集群 (一)server搭建及性能測试

    百度定义:Redis是一个key-value存储系统.和Memcached类似,它支持存储的value类型相对很多其它.包含string(字符串).list(链表).set(集合).zset(sort ...

  6. 測试之路3——对照XML文件2

    距离上一篇对照xml文件隔了非常久,并不代表一直做了那么久. 事实上上一次对照xml文件一直出错,事实上我忽略了一个非常easy的问题:我从根文件夹下得到的全部孩子,是这个根下的,而xml文件的组织形 ...

  7. JAVA-day08 下午-总结、測试

    继承总结: class { public static void main(String[] args) { System.out.println("Hello World!"); ...

  8. PCI OP WiFi 測试(二):PCI对OP的要求

    PCI OP WiFi 測试(二):PCI对OP的要求 每次看PCI的文档.都一头雾水,本来就非常抽象.看英文就感觉更抽象.泛泛而谈的要求,看一次忘一次.仅仅好翻译成中文.没事就看看,知道指导思想. ...

  9. Android自己主动化測试解决方式

    如今,已经有大量的Android自己主动化測试架构或工具可供我们使用,当中包含:Activity Instrumentation, MonkeyRunner, Robotium, 以及Robolect ...

随机推荐

  1. uva1632 (区间DP)

    题意:有n个宝藏,在x轴上,每个宝藏在某个时间会消失,问最少吃完所有宝藏的时间是多少,否则输出no solution 分析:区间DP,f[i][j][01]代表i到j区间内的全部吃完,停留在左/右端, ...

  2. github之怎么上传本地项目

    github之怎么上传本地项目 以前都是在自己磁盘上的某个目录下,然后打开git bash,来进行把本地的一些文件推到远程github上. 之前的方法步骤: 1.在github上new一个库,然后gi ...

  3. 域名做CDN来通过隐藏服务器真实IP的方法来防止DDoS攻击(转)

    隐藏服务器真实IP是解决问题最好和最快的方法,但只针对小流量,大流量同样会扛不住. 服务器前端加CDN中转,比如阿里云.百度云加速.360网站卫士.加速乐.安全宝等,如果资金充裕的话,可以购买高防的盾 ...

  4. Excel 电子表格文件格式剖析

    Excel 电子表格文件格式,这种Excel和其他的Excel是不同的.他的本质上是一个Xml文件(用英文版的UtraEdit可以看到),所以他可以保存任何符号的字符,包括&(它在Xml文件中 ...

  5. [转]Configure a Package to Use Transactions SSIS

    本文转自:http://msdn.microsoft.com/en-us/library/ms141144.aspx When you configure a package to use trans ...

  6. django admin后台接入tinymce并且支持图片上传

    首先:下载tinymce 地址是https://www.tinymce.com/ 点击download 下载社区版本即可 接着:把压缩包内tinymce目录内的所有文件和文件夹复制到Django项目中 ...

  7. metal 优化数据分析

    https://developer.apple.com/documentation/metal/render_pipeline/viewing_pipeline_statistics_of_a_dra ...

  8. mysql5.7用户密码策略问题

    密码策略问题 ERROR 1819 (HY000): Your password does not satisfy the current policy requirements 查看 mysql 初 ...

  9. 【License】一张图该诉你各种License的含义?

    一张图该诉你各种License的含义:

  10. Spark详解

    原文连接 http://xiguada.org/spark/ Spark概述 当前,MapReduce编程模型已经成为主流的分布式编程模型,它极大地方便了编程人员在不会分布式并行编程的情况下,将自己的 ...