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. js的执行环境及作用域

    主要的是执行环境和作用域链. 执行环境 执行环境定义了变量或函数有权访问的其他数据,每个函数都有一个执行环境,每个执行环境都有一个与之关联的变量对象,环境中定义的所有变量和函数都保存在这个变量对象中, ...

  2. ApplicationDelegate里的方法

    // 程序第一次加载完毕 - (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictio ...

  3. linux禁ping与限制ip登录

    以root进入linux系统,然后编辑文件icmp_echo_ignore_allvi /proc/sys/net/ipv4/icmp_echo_ignore_all将其值改为1后为禁止PING将其值 ...

  4. C#-java RSA加密解密

    using Org.BouncyCastle.Math; using Org.BouncyCastle.Crypto.Parameters; using Org.BouncyCastle.Securi ...

  5. 关于热插拔usb hotplug /proc/sys/kernel mdev udev b...

    转:http://www.360doc.com/content/10/0527/18/9922_29835045.shtml 这篇文章说的很好http://blog.chinaunix.net/u1/ ...

  6. 解决Eclipse建立Maven项目后无src/main/java资源文件夹的办法

    建立好一个Maven项目后,如果Java Resources资源文件下没有src/main/java文件夹,并且在手动创建这个文件时提示“已存在文件”.这说明,在这个项目配置中已经有了src/main ...

  7. python笔记14-读取yaml配置文件(pyyaml)

    yaml简介 1.yaml [ˈjæməl]: Yet Another Markup Language :另一种标记语言.yaml 是专门用来写配置文件的语言,非常简洁和强大,之前用ini也能写配置文 ...

  8. android非法字符的判定、表情符号的判定

    public class EmojiEditText extends EditText {// 输入表情前的光标位置private int cursorPos; // 输入表情前EditText中的文 ...

  9. Python结合Shell/Hadoop实现MapReduce

    基本流程为: cat data | map | sort | reduce cat devProbe | ./mapper.py | sort| ./reducer.py echo "foo ...

  10. PySpider 框架爬虫错误 HTTP 599: SSL certificate problem: unable to get local issuer certificate解决方案

    首先pyspider all启动pyspider的所有服务,然后访问http://localhost:5000创建一个爬虫任务:taobaomm,点开任务链接编辑http://localhost:50 ...