Lightoj 1211

来源:互联网 发布:传奇霸业注灵数据 编辑:程序博客网 时间:2024/05/19 03:43

题目链接:点这里
题意: 求n个立方体的交集的体积。
思路:x,y,z的范围<=1000, 开3个数组分别记录x轴,y轴,z轴的坐标(具体看代码)。
WA了好几次,以为当n为1的时候应该为0。

AC代码:

#include <cstdio>#include <cstring>#include <algorithm>#include <iostream>#include <stack>#include <queue>#include <vector>#include <cmath>#include <map>#include <set>#define ll long long#define llu unsigned long longusing namespace std;const int maxn = 100010;const double eps = 1e-8;const double PI  = acos(-1.0);int x[1010],y[1010],z[1010];int main(){    int T; scanf("%d",&T);    for(int cas = 1; cas<=T; cas++){        memset(x,0,sizeof(x));        memset(y,0,sizeof(y));        memset(z,0,sizeof(z));        int n;scanf("%d",&n);        for(int i=1;i<=n;i++) {            int x1,y1,z1;            int x2,y2,z2;            scanf("%d%d%d%d%d%d",&x1,&y1,&z1,&x2,&y2,&z2);            for(int j=x1; j<=x2; j++) {                x[j]++;            }            for(int j=y1; j<=y2; j++) {                y[j]++;            }            for(int j=z1; j<=z2; j++) {                z[j]++;            }        }        int t1=0,t2=0,t3=0;        for(int i=1;i<=1010; i++) {            if(x[i]==n) t1++;            if(y[i]==n) t2++;            if(z[i]==n) t3++;        }//        cout<<t1<<" "<<t2<<" "<<t3<<endl;        t1-=1; t2-=1; t3-=1;        int v = t1*t2*t3;        if(v < 0) v=0;        printf("Case %d: %d\n",cas,v);    }    return 0;}
0 0
原创粉丝点击