Codeforce 215c ideas Crosses

Source: Internet
Author: User


I have been thinking about it for a long time, but I don't know why there are only four in. After reading the hint of the original CF question, I don't know why the four are. Later, I finally understood. The two equations are very important. I did not understand the meaning of these two equations when I typed the code, so I couldn't go through it.

After reading other people's code and understanding it for a long time, you can understand it.

First, any one of these two equations can represent a rectangle (the cross can be wide ). With this in mind, the code should be no more than ten.

Let's enumerate a rectangle (the side must be an odd number). If this rectangle meets the conditions, we can enumerate the length (or width) of another rectangle (because the total area has been set ).

I really cannot afford to hurt the question of CF. I did it today from last night...

#include <cstdio>int n,m,s,r;//2 equations represents 2 rectangles!!!//so we enumerate one rectangle's hight and width//how many rectangle with h and m are there in the big given rectangle__int64 f(int h,int w){ return (n - h + 1) * (m - w + 1 );}__int64 ans;int main(){    scanf("%d%d%d",&n,&m,&s);    ans = 0;    for(int i = 1; i <= n; i += 2){//enumerate hight        for(int j = 1; j <= m && (r = s - i * j) >= 0; j += 2){            if(r == 0){//one rectangle is fairly enough        //suppose (a,b) must be i,j        //then (c,d) can have (i + 1)/2 * (j + 1)/2 choices        //then (a,b) and (c,d) can exchange, so we * 2        //but if(a,b) and (c,d) are the same,exchange them does not make any difference        //that is when a = c = i, b = d = j                ans +=( (i + 1) * (j + 1) / 2 - 1) * f(i,j);            }else                for(int k = 1; k < j; k += 2)                    if(r % (2 * k) == 0 && i + r / k <= n)                        ans += 2 * f(i + r / k, j);// (a,b) and (c,d) can exchange        }    }    printf("%I64d\n",ans);    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: 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.