zoukankan      html  css  js  c++  java
  • 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
    ", k++, ans);
    32     }
    33     rt 0;
    34 }
  • 相关阅读:
    Matrix Chain Multiplication[HDU1082]
    Color a Tree[HDU1055]
    Piggy-Bank[HDU1114]
    Catching Fish[HDU1077]
    用单位圆覆盖尽量多的点
    LianLianKan[HDU4272]
    Travelling
    求多边形面积
    方格取数(1)
    Pebbles
  • 原文地址:https://www.cnblogs.com/Duahanlang/p/3248699.html
Copyright © 2011-2022 走看看