zoukankan      html  css  js  c++  java
  • LightOJ

    Time Limit: 1000MS   Memory Limit: 32768KB   64bit IO Format: %lld & %llu

    Status

    Description

    Given an m x n chessboard where you want to place chess knights. You have to find the number of maximum knights that can be placed in the chessboard such that no two knights attack each other.

    Those who are not familiar with chess knights, note that a chess knight can attack 8 positions in the board as shown in the picture below.

     

    Input

    Input starts with an integer T (≤ 41000), denoting the number of test cases.

    Each case contains two integers m, n (1 ≤ m, n ≤ 200). Here m and n corresponds to the number of rows and the number of columns of the board respectively.

    Output

    For each case, print the case number and maximum number of knights that can be placed in the board considering the above restrictions.

    Sample Input

    3

    8 8

    3 7

    4 10

    Sample Output

    Case 1: 32

    Case 2: 11

    Case 3: 20

    Source

    Problem Setter: Jane Alam Jan

    Status

     

    题意: 棋盘上放旗子 , 原题 给了个图 , 说明了棋子会相互攻击情况,  求最多可以放多少棋子;

       观察可得, 棋子全放白的或全放黑的满足条件,

     两种特殊情况 ;

     n==1时全放上都可;

     n==2时先放满正方形的四个格,  然后空出四个格,  最后可能会出现空1, 2, 3,格情况 , 而空三格也是最多放2个 ; 得出代码--

    #include <cstdio>
    #include <algorithm>
    #include <cmath>
    using namespace std;
    int main()
    {
        int t;
        scanf("%d", &t);
        int Q=1; 
        while(t--)
        {
            int n, m;
            scanf("%d%d", &n, &m);
            if(n>m)
                swap(n, m);
            int x, y;
            x=n*m;
            x=x/2;
            y=n*m-x;
            y=max(x, y);
            if(n==1)
                x=m;
            if(n==2)
                x =2*(2*(m/4)+min(2, m%4));
            printf("Case %d: %d
    ", Q++, max(x, y));  //行*2 == 两行;
        } 
        return 0;
    }

       

       

  • 相关阅读:
    61. Rotate List
    60. Permutation Sequence
    59. Spiral Matrix II
    57. Insert Interval
    18多校8th
    2019山东省赛总结
    二分图——poj2239
    二分图匹配——poj1469
    二分图——poj2446匈牙利算法
    思维构造,建图——cf1159E
  • 原文地址:https://www.cnblogs.com/soTired/p/5330431.html
Copyright © 2011-2022 走看看