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 ...
随机推荐
- HDU 2112 HDU Today 最短路
题目描述: Problem Description 经过锦囊相助,海东集团终于度过了危机,从此,HDU的发展就一直顺风顺水,到了2050年,集团已经相当规模了,据说进入了钱江肉丝经济开发区500强.这 ...
- SSH 公钥登录
一般使用SSH进行远程登录时需要提供密码,这也是我们所熟知的一种方式. 另外,就是通过公钥登录的方式,本文将简要介绍公钥登录的两种方法,建议使用方法二.本文也将简单演示公钥登录过程,以及强制使用公钥和 ...
- NVIDIA / Intel 核芯显卡显示 + Nvidia 计算
今天折腾了好久intel集成显卡显示.最后好不容易才全部搞定,这里记录一下. 1. 首先在BIOS里是要打开Intel 核芯显卡的.我把它设置成了主显卡,显示器也接到核心显卡的口上. 重启后, I ...
- Gson学习记录
Gson是Google开发来用来序列化和反序列化json格式数据的java库,他最大的特点就是对复杂类型的支持度高,可以完美解决java泛型问题,这得益于他对泛型类型数据的特殊处理,他的缺点就是速度慢 ...
- CSS marging相关
一.margin可以为负值 在盒模型中,内容区的width/height.padding.border都不能为负值,但是margin例外,它可以为负值. margin负值的本质,在于它改变了元素在普通 ...
- 014_mac下的端口查看
一. 使用netstat去过滤listen效果不怎么理想. $ netstat -an|grep -i --color "listen" tcp6 0 0 ::1.5601 *.* ...
- MVC:分页改进URL
http://localhost/?page=2 可以根据"可组合URL"创建一种更具吸引力的URL方案: http://localhost/page2 publi ...
- Oracle数据库创建表空间
//创建表空间create tablespace ACQUISITION_DATA datafile 'F:\app\kelly\oradata\acquisition\acquisition_dat ...
- 为K8S集群建立只读权限帐号
参考URL: https://www.jianshu.com/p/a1a0d64f1245 https://mritd.me/2018/03/20/use-rbac-to-control-kubect ...
- js下判断 iframe 是否加载完成的完美方法
一般来说,我们判断 iframe 是否加载完成其实与 判断JavaScript 文件是否加载完成. 采用的方法很类似: var iframe = document.createElement( ...