LightOj1366 - Pair of Touching Circles(求矩形内圆的对数)

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

题意:一个H*W的矩形,现在要放入两个外切的圆,问能放多少对这样的圆,其中圆心和半径都是整数;

枚举相对的圆心坐标,根据圆心的距离,再枚举一个圆的半径;

#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
using namespace std;
#define met(a, b) memset(a, b, sizeof(a))
#define maxn 10005
#define maxm 20005
#define INF 0x3f3f3f3f
typedef long long LL;

int main()
{
    int T, H, W, t = 1;
    scanf("%d", &T);
    while(T--)
    {
        LL ans = 0;
        scanf("%d %d", &H, &W);
        for(int i=0; i<=W/2; i++)///把一个圆的圆心看成(0,0)时枚举另一个圆的圆心相对坐标(i,j);
        {
            for(int j=0; j<=H/2; j++)
            {
                if(i==0 && j==0) continue;
                int d = sqrt(i*i + j*j);///圆心之间的距离;
                if(d*d != i*i + j*j) continue;
                for(int r=1; r<d; r++)///枚举其中一个圆的半径;
                {
                    int x1 = min(-r, i-(d-r)), x2 = max(r, i+(d-r));
                    int y1 = min(-r, j-(d-r)), y2 = max(r, j+(d-r));///手动画图就明白了;
                    int x = x2 - x1, y = y2 - y1;
                    if(x > W || y > H) continue;
                    LL ret = (LL)(H-y+1)*(W-x+1);
                    if(i*j) ret *= 2;///*2原因是当两个圆的圆心不是水平或垂直方向的时候可以斜着放的是两种情况(斜上)(斜下),我这里的相对位置是(斜上);
                    ans += ret;
                }
            }
        }
        printf("Case %d: %lld\n", t++, ans);///%lld;
    }
    return 0;
}

时间: 2024-08-27 22:50:08

LightOj1366 - Pair of Touching Circles(求矩形内圆的对数)的相关文章

LightOJ 1366 - Pair of Touching Circles (在矩形中只需要两个圆相外切,有多少种) 半径圆心均为整数)

题意:http://www.lightoj.com/volume_showproblem.php?problem=1366 利用圆心距,将各个圆心半径都模拟出来,然后找到最小矩形  最后求出总数 #include<cstdio> #include<cstring> #include<algorithm> #include<iostream> #include<queue> #include<map> #include<vecto

25.按要求编写一个Java应用程序: (1)编写一个矩形类Rect,包含: 两个属性:矩形的宽width;矩形的高height。 两个构造方法: 1.一个带有两个参数的构造方法,用于将width和height属性初化; 2.一个不带参数的构造方法,将矩形初始化为宽和高都为10。 两个方法: 求矩形面积的方法area() 求矩形周长的方法perimeter() (2)通过继承Rect类编写一个具有

package zhongqiuzuoye; public class Rect { public double width; public double height; Rect(double width,double height) //带有两个参数的构造方法,用于将width和height属性初化; { this.width=width; this.height=height; } Rect() //不带参数的构造方法,将矩形初始化为宽和高都为10. { width=10; height=

HDU4622:Reincarnation(后缀数组,求区间内不同子串的个数)

Problem Description Now you are back,and have a task to do: Given you a string s consist of lower-case English letters only,denote f(s) as the number of distinct sub-string of s. And you have some query,each time you should calculate f(s[l...r]), s[l

HDU 1542 Atlantis (求矩形面积并)

Atlantis Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Description There are several ancient Greek texts that contain descriptions of the fabled island Atlantis. Some of these texts even include maps of parts of

HDU 1255 覆盖的面积 (求矩形面积的交)

覆盖的面积 Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Description 给定平面上若干矩形,求出被这些矩形覆盖过至少两次的区域的面积. Input 输入数据的第一行是一个正整数T(1<=T<=100),代表测试数据的数量.每个测试数据的第一行是一个正整数N(1<=N<=1000),代表矩形的数量,然后是N行数据,每一行包含四个浮点数,代表平面上的一个

经纬度计算是否在圆形内,是否在矩形内,是否在多边形内方法

class 点面关系{static void Main(string[] args){//Vector2D point1 = new Vector2D(39.909209536859834, 116.3225715637207);//inVector2D point1 = new Vector2D(39.901045, 116.415596);//outVector2D cPoint = new Vector2D(39.909209536859834, 116.3225715637207); C

求100内质数的个数

// 求100内质数的个数 非容斥 #include<iostream> #include<cstdio> #include<cstdlib> #include<algorithm> #include<cmath> #include<cstring> using namespace std; int n,sum; int main() { scanf("%d",&n); for(int i=1;i<=

使用多态求矩形的面积和周长以及圆形的面积和周长

//使用多态求矩形的面积和周长以及圆形的面积我周长 Shape shape = new Circle(5); //new Square(5,6); double area = shape.GetArea(); double perimeter = shape.GetPerimeter(); Console.WriteLine(" 这个形状的面积是{0},周长是{1}",area,perimeter); Console.ReadKey(); } public abstract class

一个关于求数组内最大子数组的和的小程序以及一周总结

一个数组内有正数和负数,而且数组是循环的.求数组内最大子数组的和.要求数组是算法空间复杂度为O(1). 思路: 1.求出每个子数组的值,比较大小. 2.定义一个参数,为数组的长度. 3.构造另外的数组,使得是原数组的得到两个集合.比如a={1,2,3,4}.b={1,2,3,4,1,2,3,4}; 4.这样可以满足数组的循环,参数为原数组的长度. 代码如下: package zuida; import java.io.*; import java.util.Scanner; class qiu