UVA 12373 Pair of Touching Circles
思路:(注意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的更多相关文章
- LightOJ 1366 - Pair of Touching Circles (统计矩形内外切圆对)
1366 - Pair of Touching Circles PDF (English) Statistics Forum Time Limit: 3 second(s) Memory Limi ...
- LightOj1366 - Pair of Touching Circles(求矩形内圆的对数)
题目链接:http://lightoj.com/volume_showproblem.php?problem=1366 题意:一个H*W的矩形,现在要放入两个外切的圆,问能放多少对这样的圆,其中圆心和 ...
- lightOJ 1366 Pair of Touching Circles(统计矩形内相切圆对)
题目链接:http://lightoj.com/volume_showproblem.php?problem=1366 题意:给出一个矩形,在内部画两个圆A和B使得AB都完全在矩形内且AB相切且AB的 ...
- 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 ...
- Codeforces Round #203 - D. Looking for Owls
D. Looking for Owls Emperor Palpatine loves owls very much. The emperor has some blueprints with the ...
- UVA 10763 Foreign Exchange 出国交换 pair+map
题意:给出很多对数字,看看每一对(a,b)能不能找到对应的(b,a). 放在贪心这其实有点像检索. 用stl做,map+pair. 记录每一对出现的次数,然后遍历看看对应的那一对出现的次数有没有和自己 ...
- UVA 10245 The Closest Pair Problem 最近点问题 分治算法
题意,给出n个点的坐标,找出两点间最近的距离,如果小于10000就输出INFINITY. 纯暴力是会超时的,所以得另辟蹊径,用分治算法. 递归思路将点按坐标排序后,分成两块处理,最近的距离不是在两块中 ...
- UVA - 247 Calling Circles Floyd判圈
思路:利用的Floyd判圈,如果i能到j,j也能到i说明i和j在同一个圈里.每个人的名字可用map编号.最后DFS打印答案即可. AC代码 #include <cstdio> #inclu ...
随机推荐
- hdu 4217 Data Structure?/treap
原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=4217 可用线段树写,效率要高点. 这道题以前用c语言写的treap水过了.. 现在接触了c++重写一遍 ...
- OC中的消息传递和初始化
[receiver message]:[接收者 消息] 把消息传递给接收者. getter(接收器),setter(设置器):只设置和读取一个参数. Person *p1 = [[Person all ...
- java数据结构和算法------选择排序
package iYou.neugle.sort; public class Select_sort { public static void SelectSort(double[] array) { ...
- Thread系列——Thread.Sleep(0)
转载自:http://www.cnblogs.com/ATually/archive/2010/10/21/1857261.html 线程这一概念,可以理解成进程中的一个小单元.这个单元是一个独立的执 ...
- (转) ASCII码对应表chr(9)、chr(10)、chr(13)、chr(32)、chr(34)、chr(39)、chr(
chr(9) tab空格 chr(10) 换行 chr(13) 回车 Chr(13)&chr(10) 回车换行 chr(32) 空格符 ...
- P1119: [POI2009]SLO
这题预处理稍微动动脑,其实还是个裸的置换群=-=,没什么压力. ; var n,i,j,minx,tem,now,tmin,len:longint; cursum,sum:int64; pos,num ...
- 解决ubuntu字体发虚,网页字体发虚
好吧,哥也不知所以然,只是突然间所有东西的字体都发虚了~~后来发现是应该是语言支持搞的鬼,卸载掉下面的东东就没事了 sudo apt-get remove fonts-arphic-ukai ttf- ...
- 如何查看系统内置的shell命令及帮助信息
1.打开终端,输入help命令可以查看系统默认的shell(通常是bash)的内置的shell命令列表: [tansheng@localhost ~]$ help GNU bash, version ...
- 树的基本操作java版
看了一下树的定义,一些基本的操作,遍历,获取节点数,获取深度等等..这里参考了西电版的数据结构,基本用的都是递归实现的. 很多说明代码中都有,每个方法我都测了一下,这里我把节点类BTreeNode作为 ...
- WooCommerce微信支付插件免费版下载
WooCommerce微信支付插件免费版下载 2016-05-11 点击:605 免费版来了 免费版终于来了,直接下载用吧,当然免费少一些功能,只有PC扫码支付,没有微信原生支付,没有汇率,没有退款, ...