• LightOJ 1366


    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 }
  • 相关阅读:
    挖矿程序linux 删除
    本地复制vue项目
    新建vue项目
    CentOS7单用户模式
    CentOS6
    CentOS6-系统管理操作
    CentOS7-系统管理操作
    VMWare克隆虚拟机
    虚拟机网络模式设置为NAT
    VI/VIM编辑器
  • 原文地址:https://www.cnblogs.com/kuangbin/p/3376608.html
Copyright © 2020-2023  润新知