BNU-pair of touching circles-mathematical questions, find a rectangle

Source: Internet
Author: User

Question:

Given a rectangle, the number of tangent circles in which the radius and center of the rectangle are integers.

Solution:

Look for a rectangle again and kneel down... The original rectangle is so useful ..

Enumerate the right-angle triangle sides to obtain the oblique edge. Enumerate the circle radius of the endpoint at the oblique endpoint and tangent at the oblique edge. A fixed rectangle is obtained from a fixed Oblique Edge and two circles. 2 is required for each rectangle due to symmetry.

In another case, if one side of a right triangle is 0, the oblique side of the enumeration is parallel to the rectangular side, and only 1 is added.

# Include <stdio. h> # include <string. h> # include <math. h> # include <map> # include <string> # include <vector> # include <set> # include <algorithm> using namespace STD; const int maxn = 1011; short int f [2000010]; int data [maxn] [maxn]; int G [maxn] [maxn]; void Init () {for (INT I = 0; I * I <= 2000000; I ++) f [I * I] = I; for (INT x = 0; x <maxn; X ++) {for (INT y = (x = 0); y <maxn; y ++) {int T = x * x + y * Y; t = f [T]; for (INT R0 = 1; R0 <t; R0 ++) {int R1 = T-R0; int u = max (x + R0 + R1, 2 * max (r0, r1); int v = max (Y + R0 + R1, 2 * max (r0, R1); If (U <1001 & V <= 1001) G [u] [v] + = 1 + (X & Y) ;}}} int main () {Init (); int Kase ,__ = 1; scanf ("% d", & Kase); While (Kase --) {int n, m; long ans = 0; scanf ("% d", & N, & M); For (INT x = 1; x <= N; X ++) for (INT y = 1; y <= m; y ++) ans = ans + (long) g [x] [Y] * (N-x + 1) * (m-y + 1); printf ("case % d: % LLD \ 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: 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.