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

枚举两个圆心的相对坐标,然后枚举其中的一个半径。

 /* ***********************************************
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 (统计矩形内外切圆对)的更多相关文章

  1. lightOJ 1366 Pair of Touching Circles(统计矩形内相切圆对)

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1366 题意:给出一个矩形,在内部画两个圆A和B使得AB都完全在矩形内且AB相切且AB的 ...

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

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1366 题意:一个H*W的矩形,现在要放入两个外切的圆,问能放多少对这样的圆,其中圆心和 ...

  3. UVA 12373 Pair of Touching Circles

    思路:(注意2个圆的半径可以不一样) 有2种情况: 1) 水平和竖直放.这种情况很简单,刚开始以为只有这种情况,但是样例5不对,后来知道还有一种情况. 2)斜线也可以放.只要满足勾股数就可以.现在的问 ...

  4. LightOJ 1414 February 29(闰年统计+容斥原理)

    题目链接:https://vjudge.net/contest/28079#problem/R 题目大意:给你分别给你两个日期(第二个日期大于等于第一个日期),闰年的2月29日称为闰日,让你求两个日期 ...

  5. Dhaka2011

    Dhaka2011 A - Binary Matrix 题目描述:有一个\(n \times m\)的\(01\)矩阵,这一矩阵第一行和最后一行是相邻的,第一列和最后一列是相邻的,现在每次可以交换相邻 ...

  6. 要back的题目 先立一个flag

    要back的题目 目标是全绿!back一题删一题! acmm7 1003 1004 acmm8 1003 1004 sysu20181013 Stat Origin Title Solved A Gy ...

  7. Spark学习笔记1——第一个Spark程序:单词数统计

    Spark学习笔记1--第一个Spark程序:单词数统计 笔记摘抄自 [美] Holden Karau 等著的<Spark快速大数据分析> 添加依赖 通过 Maven 添加 Spark-c ...

  8. Codeforces Round #203 - D. Looking for Owls

    D. Looking for Owls Emperor Palpatine loves owls very much. The emperor has some blueprints with the ...

  9. AtCoder Grand Contest 015

    传送门 A - A+...+B Problem 题意:n个数最大值a,最小值b,求和的可能数量. #include<cstdio> #include<algorithm> us ...

随机推荐

  1. scala笔记之惰性赋值(lazy)

    一.lazy关键字简介 lazy是scala中用来实现惰性赋值的关键字,被lazy修饰的变量初始化的时机是在第一次使用此变量的时候才会赋值,并且仅在第一次调用时计算值,即值只会被计算一次,赋值一次,再 ...

  2. TP-Link wr703N 使用华为HiLink系列上网卡的设置【转】

    转自:http://www.right.com.cn/forum/thread-103082-1-1.html 最近买了一个华为的E303s的上网卡,之前703的openwrt是按照需要拨号和使用U盘 ...

  3. js 加alert后才能执行方法

    原因是:访问页面时,某些js方法还没初始化(或者还没有加载出来)此时调用肯定不执行.alert起到了延迟的功能,当用户点击确定此时要执行的js恰好初始化完成,能正常执行. 解决方法是 加setTime ...

  4. vistual studio 去除 git 源代码 绑定

    第一次碰到这个问题,想将源代码签入TFS管理.添加到源码管理后,默认添加到Git源码管理. 研究过后,发现: 1)删除框内文件 2)Vs->工具->选项->源代码管理->插件管 ...

  5. 005_ss-link.info的ping探测工具

    用小工具ping.py测试距离您最快的节点 #!/usr/bin/env python # coding: utf-8 """ A pure python ping im ...

  6. poj1033

    模拟题,注意不需要移动的情况要特殊输出 #include <cstdio> #include <cstring> #include <cstdlib> using ...

  7. [转]solver优化方法

    原文地址:http://www.cnblogs.com/denny402/p/5074212.html 到目前为止,caffe总共提供了六种优化方法: Stochastic Gradient Desc ...

  8. 项目通过https访问的tomcat相关配置

    开发项目已经完成,那么就是要部署项目到服务器上面.我最近把刚完成的项目部署到服务器上面,内网通过http协议进行访问一切正常,但是测试外网通过https协议进行访问的时候就出现了一些js文档找不到的b ...

  9. pig cookbook学习

    pig cookbook学习 Overview 近期需要用pig做一些统计,由于没有系统学习,问题出现一些问题,且不容易调试,执行效率也不高.所以打算看一些官方文档,在此做些笔记. pig性能提升 指 ...

  10. VS C++ 并发编程

    1.VS2012及以上版本,支持C++11 thread类的并发编程. 相关材料可以参考博客:http://www.cnblogs.com/rangozhang/p/4468754.html 2.但对 ...