HDU-2524 Rectangle A + B

Source: Internet
Author: User

Find a regular problem, this kind of problem is more ingenious, to carefully observe and find the law

1. Assuming that there is only one row, there are n columns, then the number of rectangles consisting of a small rectangle is n, and the number of rectangles consisting of two small rectangles is n-1 .... The number of rectangles consisting of n small rectangles is 1, so the number of rectangles is

n + (n-1) + (n-2) + ... + 2 + 1 = n * (n + 1)/2

2. Similarly, suppose that there is only one column, the number of rectangles that can be formed is also n * (n + 1)/2

So, the total number of rectangles is the total number of rectangles that the row consists of the number of rectangles * columns

The code is as follows

1#include <stdio.h>2 3 intMain ()4 {5     intN, M, N;6scanf"%d", &N);7      while(n--)8     {9scanf"%d%d", &n, &m);Ten         intt = n * (n +1) /2* M * (M +1) /2;  Oneprintf"%d\n", T); A     }  -      -     return 0; the}

HDU-2524 Rectangle A + B

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.