hdoj-1046-Gridland(规律题)

题目链接

 1 #include <algorithm>
 2 #include <iostream> 
 3 using namespace std;
 4 int main()
 5 {
 6     int t;
 7     cin>>t;
 8     int j=0;
 9     while (t--) {
10         int m,n;
11         cin>>m>>n;
12         printf("Scenario #%d:
",++j);  
13         if (!(n&1) || !(m&1)) {
14             printf("%.2lf
",double(m*n));  //若n是偶数,我们可以将m的最后一列留出来和n的最下面一行,为了回来,而剩余的段走S形完全遍历;m是偶数时同理,共n*m。
15         } else {
16             printf("%.2lf
",n*m-1);  //若都是奇数时,必须走一次斜线,才能变成上面的情况。共n*m-1+sqrt(2)。
17         }
18         cout<<endl;
19     }
20     return 0;
21 }
原文地址:https://www.cnblogs.com/langyao/p/8994134.html