lightoj 1010 (水题,找规律)

lightoj 1010 Knights in Chessboard

链接:http://lightoj.com/volume_showproblem.php?problem=1010

题意:国际象棋规则,在 m*n 的格子放某一棋子,棋子可以沿着它的8个方位直走,问盘子可以放多少个这样的棋子而使任意两个不发生冲突。

思路:数学水题,找下算出几组,找下规律就出来了。值得注意的是有特判。

代码:

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cmath>
 4 #include <cstring>
 5 #include <algorithm>
 6 #include <vector>
 7 using namespace std;
 8 
 9 #define db double
10 #define cs const
11 #define sf scanf
12 #define pf printf
13 #define rt return
14 typedef long long LL;
15 
16 int main()
17 {
18     int t, m, n, ans, k = 1;
19     cin >> t;
20     while(t--)
21     {
22         sf("%d%d", &m, &n);
23         if(m > n)   swap(m, n);
24         if(m == 1)  ans = n;        //特判
25         else if(m == 2) ans = n/4*4 + min(n%4, 2)*2;    //特判
26         else {
27             ans = m*n;
28             if(ans&1)   ans++;
29             ans /= 2;
30         }
31         pf("Case %d: %d\n", k++, ans);
32     }
33     rt 0;
34 }

 

posted @ 2013-08-09 17:10  妮king狼  阅读(358)  评论(0编辑  收藏  举报