Va 11538 chess Queen

Source: Internet
Author: User

Put two attacking queens on the n × m board and ask how many methods are there

This question focuses not on programming, but on the derivation of mathematical formulas. The formula of Σ (I2) is also used. It seems that I didn't learn mathematics in high school.

As for the derivation process, read the White Paper. By the way, there seems to be a small error in the book, but it does not affect the result.

1 // # define local 2 # include <iostream> 3 # include <algorithm> 4 using namespace STD; 5 6 int main (void) 7 {8 # ifdef local 9 freopen ("11538in.txt", "r", stdin); 10 # endif11 12 unsigned long n, m; 13 while (CIN> N> m) 14 {15 if (n + M = 0) break; 16 if (n> m) Swap (n, m ); 17 cout <m * n * (m + N-2) + 2 * n * (n-1) * (3 * m-n-1)/3 <Endl; 18} 19 Return 0; 20}
Code Jun

 

Va 11538 chess Queen

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.