UVa 10751 Chess Board v.2
解題策略
注意
修正了兩個問題,終於AC了1. 雖然題目頁說只要印小數點後三位,但其實要印四位。
2. 各個output case"之間",要隔一個blank line。
但只有case間要空行,最後一個case印完後不能有多餘的空行。 (很嚴格的的格式要求...)
新版的AC Code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream< | |
#include<cmath< | |
int main() | |
{ | |
double sqrtwo = sqrt(2.0); | |
double pathLength; | |
int times, n; | |
scanf("%d", ×); | |
for (int i = 0; i < times; i++) | |
{ | |
scanf("%d", &n); | |
pathLength = (n - 1) * 4 + ( (n - 2 > 0) ? ((n - 2) * (n - 2) * sqrtwo) : (0)); | |
printf("%.4f\n", pathLength); | |
if (i != times - 1) printf("\n"); | |
} | |
return 0; | |
} |
留言
張貼留言