uva12373 - Pair of Touching Circles
2015-08-07 19:05
253 查看
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。。
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; }
相关文章推荐
- Rails中的缓存
- hive启动报错:Terminal initialization failed; falling back to unsupported
- http://blog.csdn.net/lpdx111/article/details/7638147
- hdoj-1023-Train Problem II【卡特兰数】
- hdu 5353 Average || 2015 Multi-University Training Contest 6 || 简单题
- 2015 Multi-University Training Contest 6(HDOJ5353)
- Aircrack-ng新手指南
- 2015 Multi-University Training Contest 5 hdu 5352 MZL's City
- Codeforces 538 E. Demiurges Play Again
- AIDL 分析2
- WIN7下运行hadoop程序报:Failed to locate the winutils binary in the hadoop binary path
- SLF4J: Class path contains multiple SLF4J bindings.
- CodeForces 195B After Training(STL)
- UVa 10803 Thunder Mountain (任意两点最短路的最大值+Floyd)
- 2015 Multi-University Training Contest 6
- 2015 Multi-University Training Contest 6 hdu 5358 First One
- 安卓 绑定service的aidl出现异常的解决
- MongoDB not authorized on admin to execute command --auth Authentication failed.
- hdu-5323-Solve this interesting problem(2015 Multi-University Training Contest 3)
- linux wait与waitpid函数的深入分析