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 ...
随机推荐
- ZOJ 3818 Pretty Poem
暴力模拟 细节处理很重要... #include <iostream> #include <cstring> #include <cstdio> using nam ...
- Jasper_mainReport_excel html pdf 主报表中常用属性
jasper中,excel , html, pdf 一般可以使用相同的主报表和子报表.需要在主报表中添加不同格式对应的属性.导出不同格式的报表,编译器会将相应的属性应用到对应的报表格式中. 常用属性如 ...
- iOS开发:详解Objective-C runTime
Objective-C总Runtime的那点事儿(一)消息机制 最近在找工作,Objective-C中的Runtime是经常被问到的一个问题,几乎是面试大公司必问的一个问题.当然还有一些其他问题也几乎 ...
- Unity3D TouchScript 插件教程一
只是个人学习小记,谈不上教程,但是为了命中搜索引擎关键词,只好装逼了:),可能对于大家来说太简单了吧,网上中文教程没搜到 ,只好自己摸索了. 插件资源下载地址:https://www.assetsto ...
- LeetCode_Convert Sorted Array to Binary Search Tree
Given an array where elements are sorted in ascending order, convert it to a height balanced BST. /* ...
- Android高德地图自定义Markers的例子
下文为各位重点介绍关于Android高德地图自定义Markers的例子,希望这篇文章能够让各位理解到Android高德地图自定义Markers的方法. 之前的博客里说了地图的嵌入和定位,今天就说说在地 ...
- 转:PHP的(Thread Safe与Non Thread Safe)
在安装xdebug到时候你会有有TS和NTS版本的选择,在以前还有VC6和VC9的版本.如果你没有根据你目前的服务器的状况选择对应的版本的话,那么xdebug是安装不成功的. 一.如何选择 php5. ...
- mybatis源代码分析:mybatis延迟加载机制改进
在上一篇博客<mybatis源代码分析:深入了解mybatis延迟加载机制>讲诉了mybatis延迟加载的具体机制及实现原理. 可以看出,如果查询结果对象中有一个属性是需要延迟加载的,那整 ...
- cf446C DZY Loves Fibonacci Numbers
C. DZY Loves Fibonacci Numbers time limit per test 4 seconds memory limit per test 256 megabytes inp ...
- UVa 147 Dollars(硬币转换)
题目大意:给出五种硬币,价值分别为 1,5,10,25,50,.当给出一个价值时,求出能够组合的种数(每种硬币可以用无限次). 思路:完全背包, dp[i][j]表示总数 i 能够被表示的种数.状态转 ...