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

            USACO chapter 3 section 1 Shaping Regions

            USER: tian tianbing [tbbd4261]
            TASK: rect1
            LANG: C++

            Compiling...
            Compile: OK

            Executing...
               Test 1: TEST OK [0.000 secs, 3024 KB]
               Test 2: TEST OK [0.000 secs, 3024 KB]
               Test 3: TEST OK [0.011 secs, 3024 KB]
               Test 4: TEST OK [0.000 secs, 3024 KB]
               Test 5: TEST OK [0.000 secs, 3024 KB]
               Test 6: TEST OK [0.000 secs, 3024 KB]
               Test 7: TEST OK [0.022 secs, 3024 KB]
               Test 8: TEST OK [0.011 secs, 3024 KB]
               Test 9: TEST OK [0.022 secs, 3024 KB]
               Test 10: TEST OK [0.022 secs, 3024 KB]
               Test 11: TEST OK [0.022 secs, 3024 KB]

            All tests OK.
            Your program ('rect1') produced all correct answers!  This is your
            submission #15 for this problem.  Congratulations!
             
                 終于做出來了,用隊列實現,沒接收一個就遍歷整個隊列。要注意的是要把隊列的大小用t記下,因為
            新加進來的會改變隊列的大小。
                用的是矩形分割:
            原來的程序在分割與a相交的矩形b的時候,把a與b相交的部分也作為一個小矩形放在了后面。
            這也就會多出很多,統計了一下對于最后一組測試數據有40多萬個矩形,超時。
            其實應該把a整個放進去,不該把a也分割的。



             

            /*
            ID:tbbd4261
            PROG:rect1
            LANG:C++
            */

            #include
            <fstream>
            #include
            <queue>
            #include
            <string.h>
            using namespace std;
            ifstream fin(
            "rect1.in");
            ofstream fout(
            "rect1.out");
            struct type
            {
                   
            int x1,y1,x2,y2,color;
            };

            int w,h,n,i,cnt;
            int color[2505]={0};
            queue
            <type>Q;
            inline 
            int max(int a, int b){ return a>b?a:b; }
            inline 
            int min(int a, int b){ return a>b?b:a; } 
            bool isIn(type &a, type &b)//判斷是否相交 
            {
                
            if(a.x1>=b.x2)return false;
                
            if(a.x2<=b.x1)return false;
                
            if(a.y1>=b.y2)return false;
                
            if(a.y2<=b.y1)return false;
                
            return true;
            }

            void add(int x1, int y1, int x2, int y2, int c)
            {
                  type t; t.x1
            =x1; t.y1=y1; t.x2=x2; t.y2=y2; t.color=c; 
                  color[c]
            +=(x2-x1)*(y2-y1);
                  Q.push(t);
            }

             
            void dec()
            {
                   type t
            =Q.front(); Q.pop();
                   color[t.color]
            -=(t.x2-t.x1)*(t.y2-t.y1);
            }

             
            void deal(type &a, type &b) //a與b交,b的下標是j                 
             {     
                 
            if(a.x1>b.x1&&a.x1<b.x2) add(b.x1, b.y1,a.x1,b.y2,b.color);//S1
                 if(a.x2>b.x1&&a.x2<b.x2) add(a.x2,b.y1, b.x2, b.y2,b.color); //S3
                 if(a.y1>b.y1&&a.y1<b.y2) add(max(a.x1,b.x1),b.y1,min(a.x2,b.x2),a.y1,b.color);//S2
                 if(a.y2>b.y1&&a.y2<b.y2) add(max(a.x1,b.x1),a.y2,min(a.x2,b.x2),b.y2,b.color);//S4
                 
            //add(max(a.x1,b.x1),max(a.y1,b.y1),min(a.x2,b.x2),min(a.y2,b.y2),a.color);//a與b相交的部分 
                 dec();
             }

            int main()
            {
                memset(color,
            0,sizeof color);
                fin
            >>w>>h>>n;
                color[
            1]=w*h;
                type temp;  
                temp.x1
            =0; temp.y1=0; temp.x2=w; temp.y2=h; temp.color=1;
                Q.push(temp);
                
            for(i=1; i<=n; i++)
                {
                         fin
            >>temp.x1>>temp.y1>>temp.x2>>temp.y2>>temp.color;
                         
            for(int t=Q.size(),j=1;j<=t; j++ )
                                 
            if(isIn(temp,Q.front() ))
                                      deal( temp,Q.front() );
                                 
            else { type t=Q.front(); Q.pop();Q.push(t); }//如果不相交,放在隊列后面
                    add(temp.x1,temp.y1,temp.x2,temp.y2,temp.color);
                }
                
            for(i=1; i<=2500; i++)
                          
            if(color[i]) fout<<i<<' '<<color[i]<<endl;  
                          
                
            return 0;
            }

             

            posted on 2010-08-04 16:51 田兵 閱讀(126) 評論(0)  編輯 收藏 引用 所屬分類: USACO

            <2010年5月>
            2526272829301
            2345678
            9101112131415
            16171819202122
            23242526272829
            303112345

            導航

            統計

            常用鏈接

            留言簿(2)

            隨筆分類(65)

            隨筆檔案(65)

            文章檔案(2)

            ACM

            搜索

            積分與排名

            最新隨筆

            最新評論

            閱讀排行榜

            久久99热这里只有精品国产| 美女久久久久久| 午夜精品久久久久久久久| 热久久视久久精品18| 久久久久久久久久久精品尤物 | 久久91精品国产91| 久久国产色AV免费观看| 国内精品久久久久影院日本| 热RE99久久精品国产66热| 久久狠狠高潮亚洲精品| 久久91精品综合国产首页| 囯产精品久久久久久久久蜜桃| 久久精品无码一区二区三区| 中文成人久久久久影院免费观看| 久久精品无码午夜福利理论片| 久久精品成人| 91久久国产视频| 大伊人青草狠狠久久| 久久精品亚洲中文字幕无码麻豆| 久久久久久A亚洲欧洲AV冫| 国产∨亚洲V天堂无码久久久| 亚洲欧洲精品成人久久曰影片| 婷婷综合久久狠狠色99h| 青青草原精品99久久精品66| 欧美日韩精品久久免费| 激情综合色综合久久综合| 99久久精品日本一区二区免费| 亚洲愉拍99热成人精品热久久 | 一级做a爰片久久毛片看看| 精品久久久久一区二区三区| 国产亚洲综合久久系列| 久久精品aⅴ无码中文字字幕重口| 亚洲欧美伊人久久综合一区二区| 日本精品久久久久久久久免费| 狠狠色丁香婷婷综合久久来来去 | 香蕉久久久久久狠狠色| 久久久99精品成人片中文字幕| 久久精品亚洲乱码伦伦中文| 久久天天躁狠狠躁夜夜不卡| 色天使久久综合网天天| 久久亚洲AV无码精品色午夜 |