您的位置:首页 > 其它

zoj1037

2012-03-03 17:14 375 查看
这道题把规律找出来后难度还行。主要分width*length的奇偶。当为偶数时,可以一步不重复地走完,当为奇数时,就要用平方根了。

#include<stdio.h>
#include<math.h>
int main()
{
float num;
int n;
int width,length;
int count=0;
scanf("%d",&n);
while(n)
{
scanf("%d%d",&length,&width);
if((width*length)%2)
{
num=width*length*1.0-1.0+sqrt(2);
}
else
{
num=width*length*1.0;
}
count++;
n--;
printf("Scenario #%d:\n",count);
printf("%.2f\n\n",num);

}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: