• <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年11月>
            31123456
            78910111213
            14151617181920
            21222324252627
            2829301234
            567891011

            常用鏈接

            留言簿(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里做題目的,看了你的解析,相當的蛋疼。。。完全是看不懂,汗,不過看得出你狠厲害啊!呵呵。。。。
            婷婷久久精品国产| 久久精品国产亚洲AV无码娇色| www性久久久com| 女同久久| 国产精品无码久久四虎| 99久久超碰中文字幕伊人| 色综合久久中文色婷婷| 久久久久久毛片免费播放| 一级做a爰片久久毛片人呢| 99久久99久久久精品齐齐 | 午夜视频久久久久一区| 久久精品国产日本波多野结衣| 久久影院午夜理论片无码 | 色欲综合久久中文字幕网| 久久久黄色大片| 久久大香萑太香蕉av| 欧美久久一区二区三区| 久久ww精品w免费人成| 亚洲Av无码国产情品久久| 久久精品视频免费| 九九久久精品无码专区| 99精品伊人久久久大香线蕉| 久久婷婷五月综合97色直播| 国产精品嫩草影院久久| 1000部精品久久久久久久久| 囯产精品久久久久久久久蜜桃| 无码伊人66久久大杳蕉网站谷歌| 久久国产福利免费| 91久久成人免费| 99久久免费只有精品国产| 久久99精品久久久久婷婷| 亚洲中文字幕久久精品无码喷水| 天堂无码久久综合东京热| 久久无码精品一区二区三区| 狠狠色丁香婷婷久久综合不卡| 久久久一本精品99久久精品88| 亚洲色婷婷综合久久| 热re99久久6国产精品免费| 国产午夜电影久久| 99久久国产综合精品成人影院| 国产精品成人99久久久久 |