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 ...
随机推荐
- Objective-C中release和nil的关系
(iphone/ipad)浅谈Objective-C中release和nil的关系 分类: iPhone/iPad开发技术2011-12-09 01:40 2515人阅读 评论(4) 收藏 举报 ui ...
- LeetCode_Palindrome Number
Determine whether an integer is a palindrome. Do this without extra space. Some hints: Could negativ ...
- LeetCode_Distinct Subsequences
Given a string S and a string T, count the number of distinct subsequences of T in S. A subsequence ...
- git push error: RPC failed; result=56, HTTP code = 0 ,the remote end hung up unexpectedly
git push的时候发生标题上面的错误,不知道怎么解决.搜索了下stackoverflow,上面说是http的postBuffer不够导致的. 要运行以下命令: git config --globa ...
- nm和readelf命令的区别
其实问题的本质是对elf格式的理解问题,因为是查看so库的符号表发现的问题. 事情起因是这样的,由于我的一个程序编译的时候出现了undefined reference to “XXX”的错误,需要链接 ...
- 系统监控的工具tsar
近期一直在折腾着elasticsearch,需要对硬件进行评估 大概几方面 内存 cpu 硬盘 网络. iostat vmstat top 几个命令用了一堆,其实需要关注的几个点只要都列出来就可以了 ...
- /etc/fstab 文件详解 及 /etc/mtab
/etc/fstab 文件解释 文件fstab包含了你的电脑上的存储设备及其文件系统的信息.它是决定一个硬盘(分区)被怎样使用或者说整合到整个系统中的唯一文件. 这个文件的全路径是/etc/fstab ...
- hdu 5033 Building (单调栈 或 暴力枚举 )
Description Once upon a time Matt went to a small town. The town was so small and narrow that he can ...
- redis 的基本语法
Redis::__construct构造函数 $redis = new Redis(); connect, open 链接redis服务 参数 host: string,服务地址 port: int, ...
- Python3.5 queue模块详解
queue介绍 queue是python中的标准库,俗称队列,可以直接import 引用,在python2.x中,模块名为Queue 在python中,多个线程之间的数据是共享的,多个线程进行数据交换 ...