现在的位置: 首页 > 综合 > 正文

hdu 1496

2018年12月31日 ⁄ 综合 ⁄ 共 734字 ⁄ 字号 评论关闭

poj 1480相似的题目

标记前两项的和,与第三项第四项的和比较,分成两个二重循环,

 

 

 

 

 

 

#include<stdio.h>
#include<string.h>
int mark1[2000001];
int main()
{
    int a[105];
    int b[4];
    int i,j;
    j=0;    
    int temp;
    for(i=1;i<=100;i++)
    {
        a[j]=i*i;//平方都是正整数,所以只求100个就可以了
        j++;
        
    }
    while(scanf("%d%d%d%d",&b[0],&b[1],&b[2],&b[3])!=EOF)
    {
        if(b[0]<0&&b[1]<0&&b[2]<0&&b[3]<0||b[0]>0&&b[1]>0&&b[2]>0&&b[3]>0)//不加会超时 
        {  
            printf("0\n");  
            continue;  
        }
        memset(mark1,0,sizeof(mark1));
        int q,w,e,r,t,i,j;
        for(i=0;i<100;i++)
        {
            for(j=0;j<100;j++)
            {
                temp=a[i]*b[2]+a[j]*b[3];
                if(temp<0)
                    temp+=2000001;//小于0的从1000000开始存起
                    mark1[temp]+=4;//因为a[i],a[j]有四种组合
            }
        }
        int ans=0;
        for(q=0;q<100;q++)
        {
            for(w=0;w<100;w++)
            {
                    temp=1*b[0]*a[q]+b[1]*a[w];
                    if(temp<=0)
                    {
                        ans+=(mark1[-1*temp]*4);
                    }
                    else
                       ans+=(mark1[2000001-temp]*4);//a[q],a[w]有四种组合
                }
        }
        printf("%d\n",ans);
    }
    return 0;
} 

 

【上篇】
【下篇】

抱歉!评论已关闭.