Equations(hdu 1496 二分查找+各种剪枝)
Equations
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 6927 Accepted Submission(s): 2810
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.
End of file.
#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 二分查找+各种剪枝)的更多相关文章
- 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 ...
- Pie(hdu 1969 二分查找)
Pie Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submiss ...
- Can you find it?(hdu 2141 二分查找)
Can you find it? Time Limit: 10000/3000 MS (Java/Others) Memory Limit: 32768/10000 K (Java/Others ...
- HDU 5652 India and China Origins 二分优化+BFS剪枝
题目大意:给你一个地图0代表可以通过1代表不可以通过.只要能从第一行走到最后一行,那么中国与印度是可以联通的.现在给你q个点,每年风沙会按顺序侵蚀这个点,使改点不可通过.问几年后中国与印度不连通.若一 ...
- hdu 1496 Equations hash表
hdu 1496 Equations hash表 题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1496 思路: hash表,将原来\(n^{4}\)降 ...
- hdu 2141:Can you find it?(数据结构,二分查找)
Can you find it? Time Limit: 10000/3000 MS (Java/Others) Memory Limit: 32768/10000 K (Java/Others ...
- hdu 2141 Can you find it?(二分查找)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2141 题目大意:查找是否又满足条件的x值. 这里简单介绍一个小算法,二分查找. /* x^2+6*x- ...
- HDU 4614 线段树+二分查找
Vases and Flowers 题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=4614 Problem Description Alice is s ...
- 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 ...
随机推荐
- HDU Today--hdu2112
HDU Today Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- mvc上传,下载,浏览文件功能(用uploadify插件)
类 public class UpLoadFileController : Controller { // // GET: /UpLoadFile/ public ActionResult Index ...
- unity3D射线检测敌人是否在前方
//发射一条射线,去检测玩家是否在自己面前,用来随后的发射炮弹 bool isForward = false; var TranformShootPoint = ai.WorkingMemory.Ge ...
- Blogger建立新文章 - Blog透视镜
使用Blogger,建立好Blog部落格之后,接着就是建立新文章,它是Blog部落格的灵魂,先从简单开始,来了解建立新文章的标题,文章中如何上传图片,建立卷标,及设定排程日期,定时自动发布等这些功能, ...
- HornetQ
https://github.com/flsusp/http-queue https://github.com/sfr-network-service-platforms/hq-console htt ...
- CRC校验源码分析
这两天做项目,需要用到 CRC 校验.以前没搞过这东东,以为挺简单的.结果看看别人提供的汇编源程序,居然看不懂.花了两天时间研究了一下 CRC 校验,希望我写的这点东西能够帮助和我有同样困惑的朋友节省 ...
- Keil C51编译及连接技术
主要介绍Keil C51的预处理方法如宏定义.常用的预处理指令及文件包含指令,C51编译库的选择及代码优化原理,C51与汇编混合编程的方法与实现以及超过64KB空间的地址分页方法的C51实现. 教学目 ...
- java设计模式--结构型模式--享元模式
享元模式 概述 运用共享技术有效地支持大量细粒度的对象. 适用性 当都具备下列情况时,使用Flyweight模式: 1.一个应用程序使用了大量的对象. 2.完全由于使用大量的对象,造成很大的存储开销. ...
- 完整的拆分nginx访问日志
<pre name="code" class="html"> 10.168.255.134 [09/Oct/2016:15:28:52 +0800] ...
- MLC固态硬盘,与入量是3000次P/E
固态硬盘是什么,固态硬盘寿命有多长 SSD泛指使用闪存芯片组成的SSD固态硬盘,是使用FLASH闪存颗粒作为存储单元,不再使用传统的机械存储方法,使用模拟的方式虚拟出传统 硬盘存取方式和扇区等,也可以 ...