696-How Many Knights (number theory)

Source: Internet
Author: User

696-How Many Knights (number theory)

696-How Many Knights (number theory)

Question Link

It is required to have the most server guard on a board, but they cannot attack each other. The attack scope of the server guard is shown in the figure below.

Train of Thought: After the image is painted, we will find that the upper and lower lines of the server guard are the best strategy.
(N)
(N)
(N)
But this only applies to 3*3 matrix and larger matrix, smaller points will be discussed separately.
Each position after a row or column can be placed without mutual attacks. The first two columns are required for the two rows, and the four server guard columns are not allowed for the next two columns. Therefore, the four columns and the four columns are considered.

Code:

#include 
  
   #include 
   
    #include using namespace std;int main () {    int n, m, r, c, ans;    while (scanf ("%d%d", &n, &m) && (n || m)) {        r = min(n, m);        c = max(n, m);        if (r == 2) {            int mod = c % 4;            int mul = c / 4;            ans = mul * 4 + (mod <= 2? (mod * 2) : 4);         } else if (r <= 1) {            ans = r * c;        } else {            ans = (n * m + 1) / 2;         }        printf ("%d knights may be placed on a %d row %d column board.\n", ans, n, m);    }    return 0;}
   
  

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.