[恢]hdu 1407

2011-12-20 15:23:47

地址:http://acm.hdu.edu.cn/showproblem.php?pid=1407

题意:中文。

mark:TLE了几次,没想清楚循环上界。

代码:

# include <stdio.h>
# include <math.h>


void gao(int num)
{
int x, y, z ;
int lim1 = sqrt(num),lim2 ;
for (x = 1 ; x <= lim1+1 ; x++)
{
lim2 = sqrt(num-x*x) ;
for (y = x ; y <= lim2 ; y++)
{
z = sqrt(num-x*x-y*y) ;
if (z == 0) continue ;
if (x*x + y*y+z*z == num)
{
printf ("%d %d %d\n", x, y, z) ;
return ;
}
}
}
}


int main ()
{
int num ;
while (~scanf ("%d", &num))
gao(num) ;
return 0 ;
}



posted @ 2012-01-06 23:10  Seraph2012  阅读(153)  评论(0编辑  收藏  举报