LightOJ 1366 - Pair of Touching Circles (统计矩形内外切圆对)

1366 - Pair of Touching Circles
Time Limit: 3 second(s)Memory Limit: 32 MB

You are given a rectangular grid of height H and width W. A problem setter wants to draw a pair of circles inside the rectangle so that they touch each other but do not share common area and both the circles are completely inside the rectangle. As the problem setter does not like precision problems, he also wants their centers to be on integer coordinates and their radii should be positive integers as well. How many different ways can he draw such pair of circles? Two drawings are different from each other if any of the circles has different center location or radius.

Input

Input starts with an integer T (≤ 500), denoting the number of test cases.

Each case starts with a line containing two integers H and W (0 < H, W ≤ 1000).

Output

For each case, print the case number and the number of ways of drawing such pairs of circles maintaining the mentioned constraints. Each output will fit into a 64-bit signed integer.

Sample Input

Output for Sample Input

5
4 2
4 3
4 4
4 6
10 10

Case 1: 1

Case 2: 2

Case 3: 6

Case 4: 16

Case 5: 496

Note

For case 3, the possible results are:

 


PROBLEM SETTER: MD. TOWHIDUL ISLAM TALUKDER
SPECIAL THANKS: MD. ARIFUZZAMAN ARIF, JANE ALAM JAN

 

 

链接:http://lightoj.com/volume_showproblem.php?problem=1366

 

 

枚举两个圆心的相对坐标,然后枚举其中的一个半径。

 

 1 /* ***********************************************
 2 Author        :kuangbin
 3 Created Time  :2013-10-18 17:27:32
 4 File Name     :E:\2013ACM\专题强化训练\计算几何\LightOJ1366.cpp
 5 ************************************************ */
 6 
 7 #include <stdio.h>
 8 #include <string.h>
 9 #include <iostream>
10 #include <algorithm>
11 #include <vector>
12 #include <queue>
13 #include <set>
14 #include <map>
15 #include <string>
16 #include <math.h>
17 #include <stdlib.h>
18 #include <time.h>
19 using namespace std;
20 
21 int main()
22 {
23     //freopen("in.txt","r",stdin);
24     //freopen("out.txt","w",stdout);
25     int T;
26     int w,h;
27     int iCase = 0;
28     scanf("%d",&T);
29     while(T--)
30     {
31         iCase++;
32         scanf("%d%d",&w,&h);
33         long long ans = 0;
34         //枚举两个圆心的相对坐标
35         for(int i = 0;i <= w/2;i++)
36             for(int j = 0;j <= h/2;j++)
37             {
38                 if(i == 0 && j == 0)continue;
39                 int tmp = sqrt(i*i + j*j);
40                 if(tmp*tmp != i*i + j*j)continue;
41                 //枚举其中一个圆的半径
42                 for(int k = 1;k < tmp;k++)
43                 {
44                     int y1 = min(-k,j-(tmp-k)), y2 = max(k,j+(tmp-k));
45                     int x1 = min(-k,i-(tmp-k)), x2 = max(k,i+(tmp-k));
46                     int x = x2-x1;
47                     int y = y2-y1;
48                     if(x > w || y > h)continue;
49                     long long tt = (w - x + 1)*(h - y + 1);
50                     if(i*j)tt*= 2;
51                     ans += tt;
52                 }
53             }
54         printf("Case %d: ",iCase);
55         cout<<ans<<endl;
56     }
57     return 0;
58 }

 

 

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值