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. Java并发(三):重排序

    在执行程序时为了提高性能,提高并行度,编译器和处理器常常会对指令做重排序.重排序分三种类型: 编译器优化的重排序.编译器在不改变单线程程序语义的前提下,可以重新安排语句的执行顺序. 指令级并行的重排序 ...

  2. 二叉搜索树BStree

    二叉搜索树,实际上是有点类似于二分查找.实际上很简单,就是递归.直接上代码,有点要注意的就是删除的时候,如果是左子树和右子树都存在的话,要寻找继承者(successor). import java.u ...

  3. 初识Tomcat系统架构

    俗话说,站在巨人的肩膀上看世界,一般学习的时候也是先总览一下整体,然后逐个部分个个击破,最后形成思路,了解具体细节,Tomcat的结构很复杂,但是 Tomcat 非常的模块化,找到了 Tomcat最核 ...

  4. 必知必会JVM垃圾回收——对象搜索算法与回收算法

    垃圾回收(GC)是JVM的一大杀器,它使程序员可以更高效地专注于程序的开发设计,而不用过多地考虑对象的创建销毁等操作.但是这并不是说程序员不需要了解GC.GC只是Java编程中一项自动化工具,任何一个 ...

  5. Codeforces Round #341 (Div. 2) D. Rat Kwesh and Cheese 数学

    D. Rat Kwesh and Cheese 题目连接: http://www.codeforces.com/contest/621/problem/D Description Wet Shark ...

  6. [HTML/CSS]div显示在object、embed之上~

    引言 帮一个朋友弄前端布局,一切都正常,但是嵌入object之后,div总是在object的下面,就上网找了一下解决方案,这里记录一下,好像只对flash有效. 用embed插入一个flash(比如优 ...

  7. Email the output of a concurrent program as Attachment

    This article illustrates the steps to be followed to Email a concurrent program's output. Write a pr ...

  8. redis_常见问题

    一.使用shutdown关闭服务后,使用redis-server.redis-server redis.conf.redis-cli均提示无法连接,运行命令services.msc,启动redis服务 ...

  9. 绕过WAF继续SQL注入

    Web Hacker总是生存在与WAF的不断抗争之中的,厂商不断过滤,Hacker不断绕过.WAF bypass是一个永恒的话题,不少基友也总结了很多奇技怪招.那今天我在这里做个小小的扫盲吧.先来说说 ...

  10. Android Killer

    首先,我们先看一Android界有名的大神写关于Android反编译的博客: 郭 大 侠:http://blog.csdn.net/guolin_blog/article/details/497380 ...