LightOJ1010---Knights in chessboard (regular problem)

Source: Internet
Author: User

Given a m x n chessboard where you want to place chess Knights. You have to find the number of maximum knights so can be placed in the chessboard such that no, and Knights attack each O Ther.

Those who is not familiar with Chess knights, note this a chess knight can attack 8 positions in the board as shown in th e picture below.

Input

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

Each case contains the 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 so can be placed in the board considering the above R Estrictions.
Sample Input

Output for Sample Input

3

8 8

3 7

4 10

Case 1:32

Case 2:11

Case 3:20

Problem Setter:jane Alam Jan

Regular questions
Assume n? m is even and is greater than 2
The answer is n? m / 2
Assuming that both N and M are odd and are greater than 2
And the answer is half the line. m / 2 + 1 and half of them. m/2 A
Assuming that N m is less than or equal to 2
N (m) is 1, the answer is M (n)

M (n) has a 2, then we can consider how many 2*2 lattice
With X, the answer is ( x / 2 + x % 2)? 4
The rest may have a 2*1, assuming that x is odd and cannot be placed, assuming that X is an even number that can be placed

/************************************************************************* > File Name:LightOJ1010.cpp > Author:alex > Mail: [email protected] > Created time:2015 June 08 Monday 14:24 24 seconds *************************** *********************************************/#include <functional>#include <algorithm>#include <iostream>#include <fstream>#include <cstring>#include <cstdio>#include <cmath>#include <cstdlib>#include <queue>#include <stack>#include <map>#include <bitset>#include <set>#include <vector>using namespace STD;Const DoublePI =ACOs(-1.0);Const intINF =0x3f3f3f3f;Const DoubleEPS =1e-15;typedef Long LongLL;typedefPair <int,int> PLL;intMain () {intT, Icase =1;scanf("%d", &t); while(t--) {intN, M;scanf("%d%d", &n, &m);intAns =0;if(N >=3&& m >=3) {if(n * M%2==0) {ans = n * M/2; }Else{ints = m/2+1; Ans + = (n/2+1) * s; Ans + = (n/2) * (S-1); }        }Else{if(n = =1) {ans = m; }Else if(M = =1) {ans = n; }Else{if(M = =2) {swap (n, m); }if(M <=3) {ans =4; }Else{intCNT = m/2; Ans = (CNT/2+ cnt%2) *4;if(M%2&& CNT%2==0) {ans + =2; }                }            }        }printf("Case%d:%d\n", icase++, ans); }return 0;}

LightOJ1010---Knights in chessboard (regular problem)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.