Equations

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 6927    Accepted Submission(s): 2810

Problem Description
Consider equations having the following form:

a*x1^2+b*x2^2+c*x3^2+d*x4^2=0
a, b, c, d are integers from the interval [-50,50] and any of them cannot be 0.

It is consider a solution a system ( x1,x2,x3,x4 ) that verifies the equation, xi is an integer from [-100,100] and xi != 0, any i ∈{1,2,3,4}.

Determine how many solutions satisfy the given equation.

 
Input
The input consists of several test cases. Each test case consists of a single line containing the 4 coefficients a, b, c, d, separated by one or more blanks.
End of file.
 
Output
For each test case, output a single line containing the number of the solutions.
 
Sample Input
1 2 3 -4
1 1 1 1
 
Sample Output
39088
0
 #include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <cmath>
using namespace std;
int a,b,c,d;
int s[];
int search(int mid,int k)
{
return c*s[k]+d*s[mid];
}
void init()
{
for(int i=;i<=;i++) s[i]=i*i;
}
int main()
{
int i,j,k,ans,y;
freopen("in.txt","r",stdin);
init();
while(cin>>a>>b>>c>>d)
{
ans=;
if(a>&&b>&&c>&&d>||a<&&b<&&c<&&d<){
printf("0\n");
continue;
}
for(i=;i<=;i++)
{
for(j=;j<=;j++)
{
int sum=a*s[i]+b*s[j];
if(sum>&&c>&&d>||sum<&&c<&&d<) continue;
for(k=;k<=;k++)
{
int p=-sum-c*s[k];
if(p%d==)
{
p=p/d;
if(binary_search(s+,s+,p)) ans++;
}
}
}
}
cout<<ans*<<endl;
}
}

Equations(hdu 1496 二分查找+各种剪枝)的更多相关文章

  1. Equations HDU - 1496(哈希的应用)

    Problem Description Consider equations having the following form: a*x1^2+b*x2^2+c*x3^2+d*x4^2=0 a, b ...

  2. Pie(hdu 1969 二分查找)

    Pie Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submiss ...

  3. Can you find it?(hdu 2141 二分查找)

    Can you find it? Time Limit: 10000/3000 MS (Java/Others)    Memory Limit: 32768/10000 K (Java/Others ...

  4. HDU 5652 India and China Origins 二分优化+BFS剪枝

    题目大意:给你一个地图0代表可以通过1代表不可以通过.只要能从第一行走到最后一行,那么中国与印度是可以联通的.现在给你q个点,每年风沙会按顺序侵蚀这个点,使改点不可通过.问几年后中国与印度不连通.若一 ...

  5. hdu 1496 Equations hash表

    hdu 1496 Equations hash表 题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1496 思路: hash表,将原来\(n^{4}\)降 ...

  6. hdu 2141:Can you find it?(数据结构,二分查找)

    Can you find it? Time Limit: 10000/3000 MS (Java/Others)    Memory Limit: 32768/10000 K (Java/Others ...

  7. hdu 2141 Can you find it?(二分查找)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2141 题目大意:查找是否又满足条件的x值. 这里简单介绍一个小算法,二分查找. /* x^2+6*x- ...

  8. HDU 4614 线段树+二分查找

    Vases and Flowers 题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=4614 Problem Description Alice is s ...

  9. hdu 2141 Can you find it?(二分查找变例)

    Problem Description Give you three sequences of numbers A, B, C, then we give you a number X. Now yo ...

随机推荐

  1. [linux]linux下开启wifi热点

    网上说用 ap-hotspot可以,但是我测试的时候总是在start的时候卡主,试了以前的版本也是,最后找到了下面的方法. 第一步:安装 plasma-nm 可以使用下面的命令 sudo apt-ge ...

  2. MHA环境搭建【4】manager相关依赖的解决

    mha的manager 结点依赖与mha-node软件包.所以在安装mha-manager之前要把mha-node安装上去:再者mha-manger还依赖于perl-Config-Tiny perl- ...

  3. c#添加事物(全部执行和带保存点的执行)

    全部执行 protected void Button2_Click(object sender, EventArgs e) { // 执行事务 SqlConnection con = new SqlC ...

  4. 读mongoose api 记录

    mongoose 需要在Schemas基础上进行使用 var mongoose = require('mongoose'); var Schema = mongoose.Schema; var blo ...

  5. nodejs+express Mvc站点

    nodejs+express Mvc站点 像asp.net Mvc一样开发nodejs+express Mvc站点 首先,我是个c#码农.从事Mvc开发已然4个年头了,这两年前端MVC的兴起,我也跟风 ...

  6. cf B. Fixed Points

    http://codeforces.com/contest/347/problem/B #include <cstdio> #include <cstring> #includ ...

  7. Visual studio 使用正则表达查找替换

    原文 http://www.cnblogs.com/shineqiujuan/archive/2012/07/04/2575535.html 正则表达式是查找和替换文本模式的一种简洁而灵活的表示法.  ...

  8. explorer.exe进程简单介绍

    explorer.exe是Windows程序管理器或者Windows资源管理器,它用于管理Windows图形壳,包括开始菜单.任务栏.桌面和文件管理.不过也发现有大量的恶意病毒木马插入到explore ...

  9. 自己实现的简单MVC框架(类似Struts2+Spring)

    一.框架简介 本框架是一个类似于Struts2+Spring的框架,目的在于个人钻研和技术分享,将流行技术框架Struts2.Spring中使用到的主要技术以较为简化的方式实现出来,给大家一个更直观的 ...

  10. tcp 状态示码 及 三次握手

    TCP的几个状态对于我们分析所起的作用. 在TCP层,有个FLAGS字段,这个字段有以下几个标识:SYN, FIN, ACK, PSH, RST, URG. 其中,对于我们日常的分析有用的就是前面的五 ...