uva12373 - Pair of Touching Circles
来源:互联网 发布:java汉字转拼音首字母 编辑:程序博客网 时间:2024/06/16 23:26
Given a rectangular grid of height H and width W. A problem setter wants to draw a pair of circlesinside the rectangle so that they touch each other but do not share common area and both the circlesare completely inside the rectangle. As the problem setter does not like precision he also wants theircenters on integer coordinates and their radii to be positive integers as well. How many different wayscan he draw such pair of circles? Two drawings are different from each other if any of the circles hasdifferent center location or radius.InputThe first line of input contains the number of test cases T (T ≤ 500). Each of the next T lines willcontain two integers H and W (0 < H, W ≤ 1000).OutputFor each line of input output the case number and the number of ways of drawing such pairs of circlesmaintaining the mentioned constraints. See sample output for exact formatting. The output will fitinto 64-bit signed integer.Illustration of case 3:Sample Input54 24 34 44 610 10Sample OutputCase 1: 1Case 2: 2Case 3: 6Case 4: 16Case 5: 496
N*M的矩阵,两个相邻的圆,圆心和半径都要是整数,求这两个圆在矩阵中有多少种放置情况,位置和半径不同都算。
这题坑了我一下午=。= 我竟然拿DP去做,因为一开始想错了,以为这两个圆的关系只能是横着或竖着,然而答案并不对。。怎么看我DP写的也没问题,后来才发现还可能有斜着的情况,比如两个圆心的连线是勾股三角形斜边的时候就可以。。然后我又去特判这种情况,反正最后过了样例交上去WA。。最后一想,用什么DP啊,直接枚举两个圆心的坐标差,如果圆心距离是整数的话,再枚举半径长度,算出包含这两个圆的最小矩阵是多大,再看整个矩阵中能包含多少个这样的小矩阵,特别要注意的是如果两个圆大小相同那么对称之后还是相同,这种要特判一下。交上去TLE。。发现间距只用枚举到N,M的一半,改了后终于AC。。
#include<iostream>#include<cstdio>#include<string>#include<cstring>#include<vector>#include<cmath>#include<queue>#include<stack>#include<map>#include<set>#include<algorithm>using namespace std;typedef long long LL;const LL MAXN=1010;const LL INF=0x3f3f3f3f;const LL SIGMA_SIZE=28;LL T,N,M;LL solve(LL n,LL m){ LL ret=0; for(LL i=0;i<=N/2;i++) for(LL j=0;j<=M/2;j++) if(i+j>0){ LL t=i*i+j*j; LL sq=(LL)(sqrt(t)+0.5); if(sq*sq==t){ for(LL r=1;r<=sq/2;r++){ LL x=max(i+sq,max(r*2,(sq-r)*2)),y=max(j+sq,max(r*2,(sq-r)*2)); LL tmp=(n-x+1)*(m-y+1); if(n>=x&&m>=y){ if(i!=0&&j!=0){ if(r*2!=sq) ret+=tmp*4; else ret+=tmp*2; } else{ if(r*2!=sq) ret+=tmp*2; else ret+=tmp; } } } } } return ret;}int main(){ //freopen("in.txt","r",stdin); LL cas=0; scanf("%d",&T); while(T--){ scanf("%d%d",&N,&M); printf("Case %lld: %lld\n",++cas,solve(N,M)); } return 0;}
- uva12373 - Pair of Touching Circles
- UVA 5815 - Pair of Touching Circles
- lightOJ 1366 Pair of Touching Circles
- UVa 12373 - Pair of Touching Circles
- UVALive 5815 Pair of Touching Circles
- BNU - Pair of Touching Circles - 数学题,找矩形
- UVA 5815 & LightOJ 1366 - Pair of Touching Circles
- lightoj1366Pair of Touching Circles
- Dismiss keyboard by touching background of view
- dismiss keyboard when touching outside of textfield
- TOJ Area of Circles
- 1014. Circles of Friends (35)
- 1014. Circles of Friends (35)
- Requirements of pair programming
- Requirements of pair programming
- a pair of
- a pair of
- a pair of
- 剑指Offer面试题28(java版):字符串的排列
- Spring之初见端倪——配置篇
- OC循环渐进:模拟实现多继承的两种方式
- 多线程04---超级牛逼的GCD
- DDMS使用方法
- uva12373 - Pair of Touching Circles
- js解析jison (转)
- 使用 IntelliJ IDEA 导入 Spark 最新源码
- C++(6)C风格字符串
- python编写定时器执行脚本
- Linux内核:container_of宏分析
- C++(7)动态数组
- 安卓客户端与服务器间文件的下载与上传
- android ui 积累