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. redis源码解析之dict数据结构

    dict 是redis中最重要的数据结构,存放结构体redisDb中. typedef struct dict { dictType *type; void *privdata; dictht ht[ ...

  2. ConstraintLayout导读

    ConstraintLayout是Android Studio 2.2中主要的新增功能之一,也是Google在去年的I/O大会上重点宣传的一个功能,可以把ConstraintLayout看成是一个更高 ...

  3. CountDownLatch使用场景及分析 并发测试

    原文:https://www.cnblogs.com/bqcoder/p/6089101.html CountDownLatch使用场景及分析   JDk1.5提供了一个非常有用的包,Concurre ...

  4. etcd,Docker问题汇总

    单节点etcd publish error 正在愉快的进行jenkins流程,突然发现etcd连接不上去了.重新reboot后发现日志publish error Oct :: k8s-master e ...

  5. [NS2]TCL语言基本语法

    (来自:<NS2仿真实验-多媒体和无线网络通信>) 1. 变量(Variable)和变量替换(Variable Substitution) tcl变量是在第一次使用set的指令来指派变量的 ...

  6. Cannot generate SSPI context

    请在参考如下文章前,重启服务器解决! 相信我 没错的! http://support.microsoft.com/kb/811889

  7. PowerShell中的一个switch的例子

    在这个例子中, 应该注意 Switch语句里对数字范围条件的使用 break的使用 字符串的拼接 数组的声明   ) foreach ($element in $array) { switch($el ...

  8. rsa实现js前台加密java后台解密

    前段时间写了一个rsa前台加密到后台用java解密,下面共享下实现思路: 准备工作:第三方包是必须的 bcprov-jdk15on-148.jar commons-codec-1.7.jar comm ...

  9. 详解java中的数据结构

    线性表,链表,哈希表是常用的数据结构,在进行Java开发时,JDK已经为我们提供了一系列相应的类来实现基本的数据结构.这些类均在java.util包中.本文试图通过简单的描述,向读者阐述各个类的作用以 ...

  10. hosts文件配置及主要作用

    hosts文件位于" C:\Windows\System32\drivers\etc "目录下,用于转换名字与IP地址的转换. 在浏览器中通过域名访问网站,首先查看hosts文件中 ...