hdu 1496 Equations

Equations

题意:给定一个四元二次方程的系数a,b,c,d;问有多少个解;

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}.

题目没有说清楚当a = b时,是否x1与x2可以看成一个即之后是乘以16还是要根据情况相乘;出题者意思是不考虑这些

思路:直接枚举两个x1,x2的可能的和值,在另外两个里面找出相反数的个数即可;用STL来查找重复元素的个数即可;

时间复杂度为O(n^2log(n^2)) n <= 100;

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string.h>
#include<algorithm>
#include<vector>
#include<cmath>
#include<stdlib.h>
#include<time.h>
#include<stack>
#include<set>
#include<map>
#include<queue>
using namespace std;
#define rep0(i,l,r) for(int i = (l);i < (r);i++)
#define rep1(i,l,r) for(int i = (l);i <= (r);i++)
#define rep_0(i,r,l) for(int i = (r);i > (l);i--)
#define rep_1(i,r,l) for(int i = (r);i >= (l);i--)
#define MS0(a) memset(a,0,sizeof(a))
#define MS1(a) memset(a,-1,sizeof(a))
#define MSi(a) memset(a,0x3f,sizeof(a))
#define inf 0x3f3f3f3f
#define lson l, m, rt << 1
#define rson m+1, r, rt << 1|1
typedef __int64 ll;
template<typename T>
void read1(T &m)
{
    T x=0,f=1;char ch=getchar();
    while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();}
    while(ch>=‘0‘&&ch<=‘9‘){x=x*10+ch-‘0‘;ch=getchar();}
    m = x*f;
}
template<typename T>
void read2(T &a,T &b){read1(a);read1(b);}
template<typename T>
void read3(T &a,T &b,T &c){read1(a);read1(b);read1(c);}
template<typename T>
void out(T a)
{
    if(a>9) out(a/10);
    putchar(a%10+‘0‘);
}
int A[2][10010],top,f[110];
int solve(int n,int m,int id)
{
    top = 0;
    rep1(i,1,100){
        int t = n*f[i];
        rep1(j,1,100)
            A[id][top++] = t + m*f[j];
    }
    sort(A[id],A[id] + top);
}
int main()
{
    int a,b,c,d;
    rep1(i,1,100)   f[i] = i*i;
    while(scanf("%d%d%d%d",&a,&b,&c,&d) == 4){
        if((a > 0 && b > 0 && c > 0 && d > 0) ||(a < 0 && b < 0 && c < 0 && d < 0)) out(0);
        else{
            ll ans = 0;
            solve(a,b,0);solve(c,d,1);
            rep0(i,0,top){
                ans += (upper_bound(A[1],A[1]+top,-A[0][i]) - lower_bound(A[1],A[1]+top,-A[0][i]));
            }
            out(ans*16);
        }
        puts("");
    }
    return 0;
}

时间: 2024-10-02 04:53:05

hdu 1496 Equations的相关文章

hdu 1496 Equations (暴力+hash)

题目意思: http://acm.hdu.edu.cn/showproblem.php?pid=1496 对于方程a*x1^2+b*x2^2+c*x3^2+d*x4^2=0,给出a,b,c,d,求出有多少种方法使得方程成立,xi!=0,属于[-100,100] a,b,c,d也不为0,属于[-50,50]. Sample Input 1 2 3 -4 1 1 1 1 Sample Output 39088 0 题目分析: 直接暴力的话,会100^4,,超时,我们可以把等式转化为a*x1^2+b*

hdu 1496 Equations(暴力,哈希表 剪枝)

Equations Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 5630    Accepted Submission(s): 2237 Problem Description Consider equations having the following form: a*x1^2+b*x2^2+c*x3^2+d*x4^2=0 a,

HDU - 1496 Equations (hash)

题意: 多组测试数据. 每组数据有一个方程 a*x1^2 + b*x2^2 + c*x3^2 + d*x4^2 = 0,方程中四个未知数 x1, x2, x3, x4 ∈ [-100, 100], 且都不为0. 给定a, b, c, d ∈ [-50, 50] ,且都不为0, 求上述条件下方程解的个数. 比赛的时候想到的是枚举三个,另一个可以直接算出来.但是一直TLE...结果就没做出来. 看了题解,用的hash,很巧妙.结果自己用map写还是T..最后用数组写的.     _φ(?_?? #i

hdu 1469 Equations

Equations Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 5226    Accepted Submission(s): 2079 Problem Description Consider equations having the following form: a*x1^2+b*x2^2+c*x3^2+d*x4^2=0 a,

杭电 HDU ACM 1496 Equations

Equations Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 6065    Accepted Submission(s): 2455 Problem Description Consider equations having the following form: a*x1^2+b*x2^2+c*x3^2+d*x4^2=0 a,

hdu 1496 hash+暴力

http://acm.hdu.edu.cn/showproblem.php?pid=1496 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

HDU 1840 Equations (简单数学 + 水题)(Java版)

Equations 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1840 --每天在线,欢迎留言谈论. 题目大意: 给你一个一元二次方程组,a(X^2) + b(X) + c = 0 .求X解的个数. 思路: 分别讨论二次方程与一次方程的情况,再特殊处理下 a = b = c = 0 的情况. 感想: 是时候该水水题了. Java AC代码: 1 import java.math.*; 2 import java.util.Scanner; 3

hdu 1496

Equations Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 5663    Accepted Submission(s): 2253 Problem Description Consider equations having the following form: a*x1^2+b*x2^2+c*x3^2+d*x4^2=0a, b

(hash) hdu 1496

Equations Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 6089    Accepted Submission(s): 2465 Problem Description Consider equations having the following form: a*x1^2+b*x2^2+c*x3^2+d*x4^2=0a, b