栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

poj 1188 Gleaming the Cubes

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

poj 1188 Gleaming the Cubes

#include<stdio.h>#include<string.h>#include<iostream>#include<algorithm>using namespace std;struct data{    int x1,y1,z1;    int x2,y2,z2;    data(){}    data(int _x,int _y,int _z,int _d)    {        x1=_x;y1=_y;z1=_z;        x2=_x+_d;y2=_y+_d;z2=_z+_d;    }    data(int _x1,int _y1,int _z1,int _x2,int _y2,int _z2)    {        x1=_x1;y1=_y1;z1=_z1;        x2=_x2;y2=_y2;z2=_z2;    }    bool ok()    {        return x1<x2&&y1<y2&&z1<z2;    }    int volume()    {        if(ok()) return (x2-x1)*(y2-y1)*(z2-z1);        else return 0;    }};data inter(data a,data b){    if(a.ok())        return data(max(a.x1,b.x1),max(a.y1,b.y1),max(a.z1,b.z1),min(a.x2,b.x2),min(a.y2,b.y2),min(a.z2,b.z2));    else        return data(0,0,0,-1);}int main(){    int n,x,y,z,d;    while(scanf("%d",&n),n)    {        scanf("%d%d%d%d",&x,&y,&z,&d);        data ans(x,y,z,d);        for(int i=1;i<n;i++)        { scanf("%d%d%d%d",&x,&y,&z,&d); ans=inter(ans,data(x,y,z,d));        }        printf("%dn",ans.volume());    }    return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/380138.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号