hdu 1496 Equations

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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;
}
View Code

 

以上是关于hdu 1496 Equations的主要内容,如果未能解决你的问题,请参考以下文章

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

HDU 4569 Special equations(取模)

HDU4569 Special equations

HDU 4258 斜率优化dp

导航仿真基于matlab GUI PSINS导航仿真含Matlab源码 1496期

B. Equations of Mathematical Magic