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 }

 

转载于:https://www.cnblogs.com/Duahanlang/p/3248699.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值