• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            pku 1188 Gleaming the Cubes 矩形切割

            題意是說給出n個正方體,要求求出重疊n次的子長方體體積。
            這題開始理解錯題意了,以為要求重疊的體積,懶得寫線段樹,就直接矩形切割,最壞復雜度n4,這題數據也水的可以,竟然讓我過了,后來想了下,正確的做法應該是枚舉長方體的端點,求左下角的點和右上角的點,然后直接算體積。。。
            貼個水過去的代碼吧。。
             1 # include <cstdio>
             2 using namespace std;
             3 # include <vector>
             4 # include <map>
             5 # include <algorithm>
             6 # include <iostream>
             7 struct node
             8 {
             9    int x1,x2,y1,y2,z1,z2;
            10    bool operator<(const node &pos) const
            11    {
            12         if(x1!=pos.x1) return x1<pos.x1;
            13         else if(x2!=pos.x2) return x2<pos.x2;
            14         else if(y1!=pos.y1) return y1<pos.y1;
            15         else if(y2!=pos.y2) return y2<pos.y2;
            16         else if(z1!=pos.z1) return z1<pos.z1;
            17         else return z2<pos.z2;
            18    }
            19    node(int x1,int y1,int z1,int x2,int y2,int z2)
            20    {
            21       this->x1=x1;
            22       this->y1=y1;
            23       this->x2=x2;
            24       this->y2=y2;
            25       this->z1=z1;
            26       this->z2=z2;
            27    }
            28 };
            29 map<node,int> refer;
            30 vector<int> x;
            31 vector<int> y;
            32 vector<int> z;
            33 vector<node> data;
            34 int main()
            35 {
            36 
            37   
            38     while(true)
            39     {
            40        int num,total=0;
            41        refer.clear();
            42        x.clear();
            43        y.clear();
            44        z.clear();
            45        data.clear();
            46        scanf("%d",&num);
            47        if(!num) break;
            48        while(num--)
            49        {
            50           int tx,ty,tz,len;
            51           scanf("%d%d%d%d",&tx,&ty,&tz,&len);
            52           data.push_back(node(tx,ty,tz,tx+len,ty+len,tz+len));
            53           x.push_back(tx);x.push_back(tx+len);
            54           y.push_back(ty);y.push_back(ty+len);
            55           z.push_back(tz);z.push_back(tz+len);
            56        }
            57        sort(x.begin(),x.end());
            58        vector<int>::iterator end=unique(x.begin(),x.end());
            59        while(x.end()!=end)
            60           x.pop_back();
            61        sort(y.begin(),y.end());
            62        end=unique(y.begin(),y.end());
            63        while(y.end()!=end)
            64           y.pop_back();
            65        sort(z.begin(),z.end());
            66        end=unique(z.begin(),z.end());
            67        while(z.end()!=end)
            68           z.pop_back();
            69        for(int i=0;i<data.size();i++)
            70        {
            71           vector<int>::iterator zbegin=lower_bound(z.begin(),z.end(),data[i].z1),zend=lower_bound(z.begin(),z.end(),data[i].z2),
            72                                 ybegin=lower_bound(y.begin(),y.end(),data[i].y1),yend=lower_bound(y.begin(),y.end(),data[i].y2),
            73                                 xbegin=lower_bound(x.begin(),x.end(),data[i].x1),xend=lower_bound(x.begin(),x.end(),data[i].x2);
            74           for(vector<int>::iterator zp=zbegin;zp!=zend;zp++)
            75                for(vector<int>::iterator yp=ybegin;yp!=yend;yp++)
            76                    for(vector<int>::iterator xp=xbegin;xp!=xend;xp++)
            77                    {
            78                       node tmp(*xp,*yp,*zp,*(xp+1),*(yp+1),*(zp+1));
            79                       //printf("%d %d %d %d %d %d\n",tmp.x1,tmp.y1,tmp.z1,tmp.x2,tmp.y2,tmp.z2);
            80                       
            81                       refer[tmp]++;
            82                       if(refer[tmp]==data.size())
            83                          total+=(tmp.x2-tmp.x1)*(tmp.y2-tmp.y1)*(tmp.z2-tmp.z1);
            84                    
            85                    }
            86                        
            87        }
            88        printf("%d\n",total);
            89     }
            90     return 0;
            91 }
            92 


            posted on 2010-11-06 23:19 yzhw 閱讀(147) 評論(0)  編輯 收藏 引用 所屬分類: data struct

            <2010年10月>
            262728293012
            3456789
            10111213141516
            17181920212223
            24252627282930
            31123456

            導航

            統計

            公告

            統計系統

            留言簿(1)

            隨筆分類(227)

            文章分類(2)

            OJ

            最新隨筆

            搜索

            積分與排名

            最新評論

            閱讀排行榜

            青草国产精品久久久久久| 久久91这里精品国产2020| 中文精品久久久久人妻| 青青草原综合久久大伊人| 97精品依人久久久大香线蕉97| 久久久久久曰本AV免费免费| 伊人久久精品无码二区麻豆| 久久久久99精品成人片欧美| 久久久久女教师免费一区| 日韩人妻无码精品久久免费一| 26uuu久久五月天| 精品国产乱码久久久久久呢| 国产日韩久久免费影院| 久久精品国产半推半就| 久久男人Av资源网站无码软件| 少妇久久久久久被弄到高潮 | 国产精品亚洲综合久久| 久久午夜伦鲁片免费无码| 性做久久久久久久久老女人| 久久久91精品国产一区二区三区| 久久精品免费全国观看国产| 麻豆精品久久久一区二区| 大伊人青草狠狠久久| 精品国产一区二区三区久久久狼| 欧美va久久久噜噜噜久久| 国产V综合V亚洲欧美久久| 久久国产亚洲精品无码| 国产精品免费福利久久| 国产精品免费久久| 欧美色综合久久久久久| 久久精品国产网红主播| 久久综合久久综合久久| 亚洲欧美久久久久9999 | 久久精品国产精品青草app| 色综合久久久久网| 97精品国产97久久久久久免费| 久久综合中文字幕| 性做久久久久久久久浪潮| 国产精品gz久久久| 婷婷综合久久中文字幕蜜桃三电影| 久久香蕉超碰97国产精品|