• <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>

            ACM___________________________

            ______________白白の屋
            posts - 182, comments - 102, trackbacks - 0, articles - 0
            <2010年12月>
            2829301234
            567891011
            12131415161718
            19202122232425
            2627282930311
            2345678

            常用鏈接

            留言簿(24)

            隨筆分類(332)

            隨筆檔案(182)

            FRIENDS

            搜索

            積分與排名

            最新隨筆

            最新評論

            閱讀排行榜

            評論排行榜

            MiYu原創, 轉帖請注明 : 轉載自 ______________白白の屋    

             

            題目描述:

            Cube

            Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)
            Total Submission(s): 495    Accepted Submission(s): 226


            Problem Description
            Given an N*N*N cube A, whose elements are either 0 or 1. A[i, j, k] means the number in the i-th row , j-th column and k-th layer. Initially we have A[i, j, k] = 0 (1 <= i, j, k <= N). 
            We define two operations, 1: “Not” operation that we change the A[i, j, k]=!A[i, j, k]. that means we change A[i, j, k] from 0->1,or 1->0. (x1<=i<=x2,y1<=j<=y2,z1<=k<=z2).
            0: “Query” operation we want to get the value of A[i, j, k].
             

            Input
            Multi-cases.
            First line contains N and M, M lines follow indicating the operation below.
            Each operation contains an X, the type of operation. 1: “Not” operation and 0: “Query” operation.
            If X is 1, following x1, y1, z1, x2, y2, z2.
            If X is 0, following x, y, z.
             

            Output
            For each query output A[x, y, z] in one line. (1<=n<=100 sum of m <=10000)
             

            Sample Input
            2 5 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 2 2 2 0 1 1 1 0 2 2 2
             

            Sample Output
            1 0 1
             

            題目分析 :

                  更新區間, 查詢一個點, 三維線段樹 直接無視.........數據不是很強, 所以 直接暴力就可以過, 過完發現自己的時間 在700MS 左右, 看了下rank,

            小A 榜首..... 時間竟然才62MS....果然還是要用三維樹狀數組來加速啊 . 不過一直沒理解 用 樹狀數組 解決這題的思路, 今早上終于明白了.

            畫個圖先 :

                         

            好了 , 看代碼:

            樹狀數組代碼 :

             /*

            Mail to   : miyubai@gamil.com
            My Blog   : www.baiyun.me
            Link      : http://www.cnblogs.com/MiYu  || http://www.shnenglu.com/MiYu
            Author By : MiYu
            Test      : 1
            Complier  : g++ mingw32-3.4.2
            Program   : HDU_3584
            Doc Name  : Cube
            */
            //#pragma warning( disable:4789 )
            #include <iostream>
            #include <fstream>
            #include <sstream>
            #include <algorithm>
            #include <string>
            #include <set>
            #include <map>
            #include <utility>
            #include <queue>
            #include <stack>
            #include <list>
            #include <vector>
            #include <cstdio>
            #include <cstdlib>
            #include <cstring>
            #include <cmath>
            #include <ctime>
            using namespace std;
            inline bool scan_d(int &num)  //整數輸入
            {
                    char in;bool IsN=false;
                    in=getchar();
                    if(in==EOF) return false;
                    while(in!='-'&&(in<'0'||in>'9')) in=getchar();
                    if(in=='-'){ IsN=true;num=0;}
                    else num=in-'0';
                    while(in=getchar(),in>='0'&&in<='9'){
                            num*=10,num+=in-'0';
                    }
                    if(IsN) num=-num;
                    return true;
            }
            const int MAXN = 105;
            int mat[MAXN][MAXN][MAXN];
            int low[MAXN];
            int i, j, k;
            void setLow () {
                 for ( i = 1; i <= MAXN; ++ i ) low[i] = i & (- i);
            }
            void modify ( int x, int y, int z ) {
                 for ( i = x; i <= MAXN; i += low[i] ) {
                     for ( j = y; j <= MAXN; j += low[j] ) {
                         for ( k = z; k <= MAXN; k += low[k] )
                             mat[i][j][k] ^= 1;   
                     }    
                 }    
            }
            int query ( int x, int y, int z ) {
                 int sum = 0;
                 for ( i = x; i > 0; i ^= low[i] ) {
                     for ( j = y; j > 0; j ^= low[j] ) {
                         for ( k = z; k > 0; k ^= low[k] )
                             sum += mat[i][j][k];    
                     }    
                 }    
                 return sum & 1;
            }
            int main ()
            {
                setLow ();
                int N, M;
                while ( scan_d ( N ) && scan_d ( M ) ) {
                      memset ( mat, 0, sizeof ( mat ) );
                      while ( M -- ) {
                            int x1,y1,z1,x2,y2,z2;
                            int s;  scan_d ( s ); 
                            switch ( s ) {
                                   case 1:
                                        scan_d ( x1 ); scan_d ( y1 ); scan_d ( z1 ); 
                                        scan_d ( x2 ); scan_d ( y2 ); scan_d ( z2 );
                                        modify ( x1,y1,z1 );    modify ( x1,y1,z2+1 );
                                        modify ( x2+1,y1,z1 );    modify ( x2+1,y1,z2+1 );
                                        modify ( x1,y2+1,z1 );    modify ( x2+1,y2+1,z1 );
                                        modify ( x2+1,y2+1,z2+1 );    modify ( x1,y2+1,z2+1 ); 
                                        break;
                                   case 0:
                                        scan_d ( x1 ); scan_d ( y1 ); scan_d ( z1 );
                                        printf ( "%d\n", query ( x1,y1,z1 ) );      
                            }
                      }           
                }
                return 0;
            }
            

            暴力代碼 :

            /*
            Mail to   : miyubai@gamil.com
            My Blog   : www.baiyun.me
            Link      : http://www.cnblogs.com/MiYu  || http://www.shnenglu.com/MiYu
            Author By : MiYu
            Test      : 1
            Complier  : g++ mingw32-3.4.2
            Program   :
            Doc Name  :
            */
            //#pragma warning( disable:4789 )
            #include <iostream>
            #include <fstream>
            #include <sstream>
            #include <algorithm>
            #include <string>
            #include <set>
            #include <map>
            #include <utility>
            #include <queue>
            #include <stack>
            #include <list>
            #include <vector>
            #include <cstdio>
            #include <cstdlib>
            #include <cstring>
            #include <cmath>
            #include <ctime>
            using namespace std;
            struct node {  
                int x1, x2, y1, y2, z1, z2; 
            }cube[10010];   
              
            int main()  
            {  
                int N, M;  
                int x, y, z;
                while ( scanf ( "%d%d",&N,&M ) != EOF )  {  
                    int cnt = 0;  
                    while ( M -- )  
                    {  
                        int ask;  
                        scanf ( "%d", &ask );  
                        switch ( ask ) {
                            case 1:   
                                scanf ( "%d%d%d%d%d%d", &cube[cnt].x1,&cube[cnt].y1,
                                                        &cube[cnt].z1,&cube[cnt].x2,
                                                        &cube[cnt].y2,&cube[cnt].z2 );  
                                ++ cnt;  
                                break;
                            case 0:
                                scanf ( "%d%d%d", &x, &y, &z);  
                                int count = 0;  
                                for ( int i = 0; i != cnt; ++ i )  
                                    if ( cube[i].x1 <= x && x <= cube[i].x2 && 
                                         cube[i].y1 <= y && y <= cube[i].y2 && 
                                         cube[i].z1 <= z && z <= cube[i].z2 )  
                                                count ^= 1;;  
                                puts ( count ? "1" : "0" ); 
                        }  
                    }  
                }  
                return 0;  
            }  
            

             

            Feedback

            # re: HDU 3584 HDOJ 3584 Cube ACM 3584 IN HDU  回復  更多評論   

            2010-11-14 21:40 by 博客之家
            好復雜的代碼啊

            # re: HDU 3584 HDOJ 3584 Cube ACM 3584 IN HDU  回復  更多評論   

            2010-12-03 01:59 by flagman
            說兩點,
            1)這三維樹狀數組,占空間比較大,特別是問題規模快速增長時;
            2)對于
            void setLow () {
            for ( i = 1; i <= MAXN; ++ i ) low[i] = i & (- i);
            }
            這樣的短函數,topcoder上很多人都喜歡用宏定義,不知道為啥,難道受C的影響太深了,抑或為了節約函數調用開銷?呵呵,比如上面這函數,可能寫成如下,
            #define SETLOW(low,MAXN) for( i = 1; i <= (MAXN); ++i) *((low) + i) = i & (-i);

            # re: HDU 3584 HDOJ 3584 Cube ACM 3584 IN HDU  回復  更多評論   

            2011-04-07 19:51 by
            你好,我是一個代碼初學者,也是在HD里做題目的,看了你的解析,相當的蛋疼。。。完全是看不懂,汗,不過看得出你狠厲害??!呵呵。。。。
            无码人妻久久一区二区三区| 国产精品对白刺激久久久| 亚洲国产精品久久久久婷婷软件| 国产成人精品久久亚洲| 久久www免费人成看片| 国产成人精品久久一区二区三区av| 精品少妇人妻av无码久久| 久久91精品国产91久久小草| 人妻无码精品久久亚瑟影视| 久久综合狠狠色综合伊人| 亚洲AV日韩AV永久无码久久| 国内精品久久久久影院日本| 国内精品久久久久国产盗摄| 高清免费久久午夜精品| 97久久国产露脸精品国产| 久久综合九色欧美综合狠狠 | 久久久一本精品99久久精品88| 午夜精品久久影院蜜桃| 观看 国产综合久久久久鬼色 欧美 亚洲 一区二区| 国产精品99久久久久久猫咪| 欧洲精品久久久av无码电影| 婷婷五月深深久久精品| 久久se精品一区二区影院| 久久99精品国产自在现线小黄鸭 | 一级做a爱片久久毛片| 国产精品久久久久久久app| 一本大道久久a久久精品综合| 久久久精品人妻一区二区三区四| 狠狠色丁香婷婷久久综合五月| 久久97久久97精品免视看| 青青草国产精品久久| 久久精品天天中文字幕人妻| 97久久婷婷五月综合色d啪蜜芽| 欧美日韩精品久久久久| 久久亚洲国产成人精品无码区| 国产精品综合久久第一页| 91精品国产色综久久 | 国产福利电影一区二区三区久久老子无码午夜伦不 | 无码国产69精品久久久久网站| 久久综合亚洲色一区二区三区| 91麻豆国产精品91久久久|