思路:(注意2个圆的半径可以不一样)

有2种情况:

1) 水平和竖直放。这种情况很简单,刚开始以为只有这种情况,但是样例5不对,后来知道还有一种情况。

2)斜线也可以放。只要满足勾股数就可以。现在的问题是怎样确定包含2个圆的矩形,可以通过枚举一个圆的半径

来确定。

代码如下:

 #include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<set>
#include<vector>
#define ll long long
#define M 1000
#define inf 1e10
#define mod 1000000007
using namespace std;
int n,m,cnt;
struct node
{
int x,y,t;
}p[M];
void init()
{
cnt=;
for(int i=;i<;i++)
for(int j=i+;j<;j++){
int k=i*i+j*j;
int t=(int)sqrt(1.0*k);
if(t>M) break;
if(k==t*t){
p[cnt].x=i;
p[cnt].t=t;
p[cnt++].y=j;
}
}
}
ll cal(int a,int b)
{
int u=a+b;
int v=b;
ll ans=,t=;
if(u<=n&&v<=m) t=(n-u+)*(m-v+);
if(v<=n&&u<=m) t+=(m-u+)*(n-v+);
if(a!=b) t=*t;
ans+=t;
return ans;
}
int main()
{
int i,j,k,c,t,ca=;
init();
scanf("%d",&t);
while(t--){
scanf("%d%d",&n,&m);
ll ans=;
for(i=;i<=n||i<=m;i+=){
for(j=i;i+j<=n||i+j<=m;j+=)
ans+=cal(i,j);
}
for(i=;i<cnt;i++)
for(j=;j<p[i].t;j++){
int u=max(p[i].x+p[i].t,*max(j,p[i].t-j));
int v=max(p[i].y+p[i].t,*max(j,p[i].t-j));
ll tt=;
if(u<=n&&v<=m) tt=(n-u+)*(m-v+);
if(u<=m&&v<=n) tt+=(m-u+)*(n-v+);
ans+=*tt;
}
printf("Case %d: %lld\n",++ca,ans);
}
return ;
}

UVA 12373 Pair of Touching Circles的更多相关文章

  1. LightOJ 1366 - Pair of Touching Circles (统计矩形内外切圆对)

    1366 - Pair of Touching Circles   PDF (English) Statistics Forum Time Limit: 3 second(s) Memory Limi ...

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

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

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

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

  4. Dhaka2011

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

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

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

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

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

  7. UVA 10763 Foreign Exchange 出国交换 pair+map

    题意:给出很多对数字,看看每一对(a,b)能不能找到对应的(b,a). 放在贪心这其实有点像检索. 用stl做,map+pair. 记录每一对出现的次数,然后遍历看看对应的那一对出现的次数有没有和自己 ...

  8. UVA 10245 The Closest Pair Problem 最近点问题 分治算法

    题意,给出n个点的坐标,找出两点间最近的距离,如果小于10000就输出INFINITY. 纯暴力是会超时的,所以得另辟蹊径,用分治算法. 递归思路将点按坐标排序后,分成两块处理,最近的距离不是在两块中 ...

  9. UVA - 247 Calling Circles Floyd判圈

    思路:利用的Floyd判圈,如果i能到j,j也能到i说明i和j在同一个圈里.每个人的名字可用map编号.最后DFS打印答案即可. AC代码 #include <cstdio> #inclu ...

随机推荐

  1. 安装MySQL的心得

    1.去官网上下载适合自己电脑的安装包,最好在网上查查教程起码知道自己应该怎么下载,下载哪一个. 2.我遇到的问题不多:<1>.没在bin目录下安装,启动数据库时出现错误2:<2> ...

  2. 在.net程序中使用System.Net.Mail来发送邮件

    System.Net.Mail是微软自家提供的工具,在.net程序中可以使用该空间中的SmtpClient实例来实现邮件的发送. 使用System.Net.Mail空间与Web.config配置相配合 ...

  3. Android Studio SDK 更新方法

    通常情况下,下载Android SDK需要连接谷歌的服务器进行下载,由于国内水深火热的网络,速度基本为0.好在国内也有一个更新的镜像地址.本文章介绍如何在不FQ的情况下,使用国内镜像地址,更新andr ...

  4. mysql substring_index

    select * from tablename where substring_index(field1,'_',-1)=‘abc' #表中field1的值结构为123_abc

  5. pb datawindow 判断是否是最后一列最后一行

    li_column1 = GetColumn() ls_columnname = GetColumnName() Send(Handle(This),,,Long(,)) ll_row2 = GetR ...

  6. 通过 CALayer 修改 UIImageView 的界面属性

    界面属性的修改是每一个开发者必须知道的,为什么我就记不住呢, shit, 又耽误了时间,为了防止再找不到,特把一些常用的 CALayer属性记在这里,顺便分享 1.设置阴影 1 imageView.l ...

  7. Log4Net学习【二】

    Log4Net结构详解 当我们在描述为系统做日志这个动作的时候,实际上描述了3个点:做日志,其实就是在规定,在什么地方 用什么日志记录器 以什么样的格式做日志.把三个最重要的点抽取出来,即什么地方,日 ...

  8. 【转】linux root用户ifconfig报command not found

    解决办法: 方法一: 直接输入su - 回车.就可以ifconfig了 方法二: /etc/profile 把下面if语句注释掉: #path Manipulation if ["EUID& ...

  9. C/C++常用头文件及函数汇总

    转自: C/C++常用头文件及函数汇总 C/C++头文件一览 C #include <assert.h> //设定插入点#include <ctype.h> //字符处理#in ...

  10. 阿里云:linux 一键安装web环境

    参考地址:http://www.cnblogs.com/ada-zheng/p/3724957.html