LightOJ 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 |
Case 1: 1 Case 2: 2 Case 3: 6 Case 4: 16 Case 5: 496 |
Note
For case 3, the possible results are:
链接:http://lightoj.com/volume_showproblem.php?problem=1366
枚举两个圆心的相对坐标,然后枚举其中的一个半径。
/* ***********************************************
Author :kuangbin
Created Time :2013-10-18 17:27:32
File Name :E:\2013ACM\专题强化训练\计算几何\LightOJ1366.cpp
************************************************ */ #include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std; int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int T;
int w,h;
int iCase = ;
scanf("%d",&T);
while(T--)
{
iCase++;
scanf("%d%d",&w,&h);
long long ans = ;
//枚举两个圆心的相对坐标
for(int i = ;i <= w/;i++)
for(int j = ;j <= h/;j++)
{
if(i == && j == )continue;
int tmp = sqrt(i*i + j*j);
if(tmp*tmp != i*i + j*j)continue;
//枚举其中一个圆的半径
for(int k = ;k < tmp;k++)
{
int y1 = min(-k,j-(tmp-k)), y2 = max(k,j+(tmp-k));
int x1 = min(-k,i-(tmp-k)), x2 = max(k,i+(tmp-k));
int x = x2-x1;
int y = y2-y1;
if(x > w || y > h)continue;
long long tt = (w - x + )*(h - y + );
if(i*j)tt*= ;
ans += tt;
}
}
printf("Case %d: ",iCase);
cout<<ans<<endl;
}
return ;
}
LightOJ 1366 - Pair of Touching Circles (统计矩形内外切圆对)的更多相关文章
- lightOJ 1366 Pair of Touching Circles(统计矩形内相切圆对)
题目链接:http://lightoj.com/volume_showproblem.php?problem=1366 题意:给出一个矩形,在内部画两个圆A和B使得AB都完全在矩形内且AB相切且AB的 ...
- LightOj1366 - Pair of Touching Circles(求矩形内圆的对数)
题目链接:http://lightoj.com/volume_showproblem.php?problem=1366 题意:一个H*W的矩形,现在要放入两个外切的圆,问能放多少对这样的圆,其中圆心和 ...
- UVA 12373 Pair of Touching Circles
思路:(注意2个圆的半径可以不一样) 有2种情况: 1) 水平和竖直放.这种情况很简单,刚开始以为只有这种情况,但是样例5不对,后来知道还有一种情况. 2)斜线也可以放.只要满足勾股数就可以.现在的问 ...
- LightOJ 1414 February 29(闰年统计+容斥原理)
题目链接:https://vjudge.net/contest/28079#problem/R 题目大意:给你分别给你两个日期(第二个日期大于等于第一个日期),闰年的2月29日称为闰日,让你求两个日期 ...
- Dhaka2011
Dhaka2011 A - Binary Matrix 题目描述:有一个\(n \times m\)的\(01\)矩阵,这一矩阵第一行和最后一行是相邻的,第一列和最后一列是相邻的,现在每次可以交换相邻 ...
- 要back的题目 先立一个flag
要back的题目 目标是全绿!back一题删一题! acmm7 1003 1004 acmm8 1003 1004 sysu20181013 Stat Origin Title Solved A Gy ...
- Spark学习笔记1——第一个Spark程序:单词数统计
Spark学习笔记1--第一个Spark程序:单词数统计 笔记摘抄自 [美] Holden Karau 等著的<Spark快速大数据分析> 添加依赖 通过 Maven 添加 Spark-c ...
- Codeforces Round #203 - D. Looking for Owls
D. Looking for Owls Emperor Palpatine loves owls very much. The emperor has some blueprints with the ...
- AtCoder Grand Contest 015
传送门 A - A+...+B Problem 题意:n个数最大值a,最小值b,求和的可能数量. #include<cstdio> #include<algorithm> us ...
随机推荐
- __new__[转载]
转载自https://www.cnblogs.com/MnCu8261/p/6365665.html 实际上,实例化类时调用的第一个方法并不是__init__,而是__new__,其作用正是创建并返回 ...
- MySQL多源复制【转】
什么是多源复制? 首先,我们需要清楚 multi-master 与multi-source 复制不是一样的. Multi-Master 复制通常是环形复制, 你可以在任意主机上将数据复制给其他主机. ...
- 搜索引擎ElasticSearchV5.4.2系列二之ElasticSearchV5.4.2+kibanaV5.4.2+x-packV5.4.2安装
相关博文: 搜索引擎ElasticSearchV5.4.2系列一之ES介绍 搜索引擎ElasticSearchV5.4.2系列二之ElasticSearchV5.4.2+klanaV5.4.2+x-p ...
- linux使用badblocks命令扫描硬盘排除故障(待验证)
检查硬盘是否产生坏道并输出# badblocks -s -v -o /root/badblocks.log /dev/sda //公司操作 -s Show the p ...
- 网易与Google合作发布开源UI自动化测试方案 牛逼:Google 方面评价,这可能是目前世界上最好的 Android 游戏自动化测试方案。
美西时间 3 月 19 日,在 GDC 开幕第一天的 Google 开发者专场,Google 发布了一款由网易研发的 UI 自动化测试方案:Airtest Project.Google 方面评价,这可 ...
- IntelliJ IDEA 中安装junit插件
1.在Intellij IDEA 中安装了 Junit,TestNG插件,首先检查一下intellij IDEA 是否在安装时默认安装了这两个插件,检查方法 打开 settings -->Plu ...
- H5新增语义化标签
一.根据页面的结构,由div派生的标签. <header> <footer> <nav> 导航 在H4中导航栏一般用ul-li标签,H5中可以直接用<nav& ...
- darknet
darknet第二作者:https://github.com//AlexeyAB/darknet#how-to-train-to-detect-your-custom-objects yolov3实现 ...
- 一个洛谷Material化的Stylish美化主题
Luogu Argon Design 新主题 Luogu Argon Design 目前已经取代了 Luogu Material,但这并不代表 Luogu Material 会停止更新,在 Luogu ...
- thinkphp AOP(面向切面编程)
AOP: 在软件业,AOP为Aspect Oriented Programming的缩写,意为:面向切面编程,通过预编译方式和运行期动态代理实现程序功能的统一维护的一种技术.AOP是OOP的延续,是软 ...