zoukankan      html  css  js  c++  java
  • hdu 1496 equations(哈希)

    http://acm.hdu.edu.cn/showproblem.php?pid=1496

    题意:

    给出 a b c d 的值

    求出满足公式 a*x1^2+b*x2^2+c*x3^2+d*x4^2=0 

     的排列数

    思路:

    将公式化为 a*x1^2+b*x2^2=-c*x3^2+-d*x4^2

    哈希求左式的值

    再哈希右式 并加上对应的值  t=(upper_bound(num1,num1+coun,-temp)-lower_bound(num1,num1+coun,-temp))

    累加出ans

    #include<stdio.h>
    #include<string.h>
    #include<math.h>
    #include<iostream>
    #include<algorithm>
    using namespace std;
    int num1[12000];
    int main()
    {
        int a,b,c,d,i,j;
        while(scanf("%d%d%d%d",&a,&b,&c,&d)!=EOF)
        {
            if(a>0&&b>0&&c>0&&d>0||a<0&&b<0&&c<0&&d<0) {printf("0
    ");continue;}       
            int coun=0;
            for(i=1;i<=100;i++)
            {
                for(j=1;j<=100;j++)
                {
                    num1[coun++]=a*i*i+b*j*j;
                }
            }
            sort(num1,num1+coun);
            int cnt=0;
            for(i=1;i<=100;i++)
            {
                for(j=1;j<=100;j++)
                {
                    int t;
                    int temp=c*i*i+d*j*j;
                    if(t=(upper_bound(num1,num1+coun,-temp)-lower_bound(num1,num1+coun,-temp)))
                    cnt+=t;
                }
            }
            printf("%d
    ",cnt*16);//*2*2*2
        }
        return 0;
    }
    

      

  • 相关阅读:
    数组的学习(一)
    Servlet是线程安全吗?
    MySql用户管理:添加用户、授权、删除用户
    泛型(二)
    泛型(一)
    Spring MVC
    spring框架
    mybatis基础
    Hibernate 基础
    Java局部类
  • 原文地址:https://www.cnblogs.com/sola1994/p/3900411.html
Copyright © 2011-2022 走看看