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

poj 1840

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

求出两项的和,跟后三项比较

用int只能开数组开到12500000内存达到49000,可以用

用short 省一半内存

 

 

 

 

 

#include<stdio.h>
#include<string.h>
short mark1[12500001];
int main()
{
	int a[10005];
	int b[5];
	int i,j;
	j=0;
	
	int temp;
	for(i=-50;i<=50;i++)
	{
		if(i==0)
			continue;
		a[j]=i*i*i;
		j++;
		
	}
	while(scanf("%d%d%d%d%d",&b[0],&b[1],&b[2],&b[3],&b[4])!=EOF)
	{
		memset(mark1,0,sizeof(mark1));
		int q,w,e,r,t,i,j;
		for(i=0;i<100;i++)
		{
			if(!a[i])continue;
			for(j=0;j<100;j++)
			{
				if(!a[j])continue;
				temp=a[i]*b[3]+a[j]*b[4];
				if(temp<0)
					mark1[-1*temp]++;
				else if(temp>0)
					mark1[temp]++;
				else mark1[temp]+=2;
			}
		}
		__int64 ans=0;
		int temp;
		for(q=0;q<100;q++)
		{
			for(w=0;w<100;w++)
				for(e=0;e<100;e++)
				{
					temp=b[0]*a[q]+b[1]*a[w]+b[2]*a[e];
					if(temp>12500000||temp<=-12500000)continue;//前两项的区间是[-12500000,12500000],
					//三项的和最大达到18750000;
					if(temp<=0)
					{
						temp=-1*temp;
						ans+=mark1[temp];
					}
					else 
						ans+=mark1[temp];
				}
		}
		printf("%I64d\n",ans/2);
	}
	return 0;
} 

 

【上篇】
【下篇】

抱歉!评论已关闭.