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:\n",++j);  
13         if (!(n&1) || !(m&1)) {
14             printf("%.2lf\n",double(m*n));  //若n是偶数,我们可以将m的最后一列留出来和n的最下面一行,为了回来,而剩余的段走S形完全遍历;m是偶数时同理,共n*m。
15         } else {
16             printf("%.2lf\n",n*m-1);  //若都是奇数时,必须走一次斜线,才能变成上面的情况。共n*m-1+sqrt(2)。
17         }
18         cout<<endl;
19     }
20     return 0;
21 }

 

posted @ 2018-05-05 11:16  朤尧  阅读(271)  评论(0编辑  收藏  举报