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 ...
随机推荐
- iOS 处理缓存的三种方法
缓存处理是个相当头疼的事情,要根据需要综合应用不同的策略.总的来说有以下几种情况: 1.URL缓存,例如社交应用的帖子浏览,要在viewDidAppear:里面进行URL缓存.简单来说就是用NSURL ...
- P4549 【模板】裴蜀定理
题目描述 给出n个数(A1...An)现求一组整数序列(X1...Xn)使得S=A1X1+...AnXn>0,且S的值最小 输入输出格式 输入格式: 第一行给出数字N,代表有N个数 下面一行给出 ...
- Loadrunner里面的深入理解Resource 的 0和1
最近在倒腾loadrunner,发现一些非常有意思的配置项,也许同学们平时去玩的时候,没有注意这些点.我也查阅了网上的帖子,说的都不够详细~操作起来的话,同学们也只是看到文字的描述,并不能发现区别.今 ...
- 【译】在Asp.Net Core 中使用外部登陆(google、微博...)
原文出自Rui Figueiredo的博文<External Login Providers in ASP.NET Core> (本文很长) 摘要:本文主要介绍了使用外部登陆提供程序登陆的 ...
- poj1142
分解质因数 #include <iostream> #include <cmath> using namespace std; int sum(int n) { ; ) { a ...
- Python 驱动 MongoDB 示例(PyMongo)
Python 的MongoDB驱动 pymongo ,使用pip Install pymongo安装即可 最近发现网上的很多实例已经过时了,在此自我探究记录下来. 编写一个接口类来支持MongoDB的 ...
- .NetCore 中使用AppMetrics向InfluxDB中添加监控数据并通过Grafana图像分析
考虑到分布式部署监控环境是所有的请求情况,所以这一块一般在网关GateWay里面加比较省事,聚合在一起的,如果放在api服务中,如果只有1个还好,一旦部署Node多是很痛苦的事情 这天需要添加的Nug ...
- .NetCore 使用Jenkins发布多环境下的项目并适配数据库EFCore数据库更新及替换配置文件
说明 1.git上的配置地址可能都是本地环境,提交到git server后怎么来使用发布不同环境? 2.关于EFCore本地数据库有更新的情况 添加了 Migrations文件 怎么在构建的时候去更新 ...
- Git(一)Git的简介安装
一.git历史 同生活中的许多伟大事件一样,Git 诞生于一个极富纷争大举创新的年代.Linux 内核开源项目有着为数众广的参与者.绝大多数的 Linux 内核维护工作都花在了提交补丁和保存归档的繁琐 ...
- 微信隐藏的webJS Api汇总
1.右侧菜单增加"查看公众账号" API document.getElementById('post-user').addEventListener('click', functi ...