“玲珑杯”ACM比赛 Round #18 A -- 计算几何你瞎暴力

来源:互联网 发布:网络棋牌牛牛作弊器app 编辑:程序博客网 时间:2024/06/04 23:27

题目链接 :计算几何你瞎暴力

题目大意:在三维空间里面有一些点,现在给你一个R,问有多少对点之间的距离是不大于R的

题目思路:面向数据编程,我们看到x,y,z的范围是[0,10],那么也就是说三个点之间的距离最大为30,那么我们是不是就可以直接去枚举这0到30的距离分别有多少个就行了,具体思路看代码

#include <bits/stdc++.h>using namespace std;const int maxn = 1e6+10;typedef long long ll;int main(){    ll t,n,q,r,x,y,z;    ll cot[15][15][15],mp[55],sum[35],ans;    scanf("%lld",&t);    while(t--){        scanf("%lld%lld",&n,&q);        memset(cot,0,sizeof(cot));        memset(mp,0,sizeof(mp));        for(int i = 0;i < n;i++)            scanf("%lld%lld%lld",&x,&y,&z),cot[x][y][z]++;        for(int i = 0;i <= 10;i++)            for(int j = 0;j <= 10;j++)                for(int k = 0;k <= 10;k++)                    for(int a = 0;a <= 10;a++)                        for(int b = 0;b <= 10;b++)                                for(int c = 0;c <= 10;c++){                                    ans = abs(i-a)+abs(j-b)+abs(k-c);                                    if(i == a&&j == b&&k == c)                                        mp[ans] += (cot[i][j][k]*(cot[i][j][k]-1))/2;                                    else mp[ans] += (cot[i][j][k]*cot[a][b][c]);                                }        for(int i = 1;i <= 30;i++)            mp[i] /= 2;        sum[0] = mp[0];        for(int i = 1;i <= 30;i++)            sum[i] = sum[i-1]+mp[i];        while(q--){            scanf("%lld",&r);            if(r >= 30) printf("%lld\n",(n*(n-1))/2);            else printf("%lld\n",sum[r]);        }    }    return 0;}
阅读全文
0 0
原创粉丝点击