• <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 田兵 閱讀(118) 評論(0)  編輯 收藏 引用 所屬分類: USACO

            <2010年6月>
            303112345
            6789101112
            13141516171819
            20212223242526
            27282930123
            45678910

            導航

            統計

            常用鏈接

            留言簿(2)

            隨筆分類(65)

            隨筆檔案(65)

            文章檔案(2)

            ACM

            搜索

            積分與排名

            最新隨筆

            最新評論

            閱讀排行榜

            久久精品中文字幕久久| 国内精品久久久久久99蜜桃| 狠狠色丁香婷婷久久综合不卡| 久久天天日天天操综合伊人av| 偷窥少妇久久久久久久久| aaa级精品久久久国产片| 国内精品伊人久久久影院| 欧洲成人午夜精品无码区久久| 久久99国产精品99久久| 久久国产精品波多野结衣AV| www.久久热| 7777精品伊人久久久大香线蕉| 久久综合国产乱子伦精品免费 | 伊人久久大香线蕉综合网站| jizzjizz国产精品久久| 中文字幕久久欲求不满| 青青草原1769久久免费播放| 久久久久黑人强伦姧人妻| 久久精品国产亚洲av瑜伽| 久久久噜噜噜久久中文字幕色伊伊| 少妇久久久久久被弄到高潮| 国产免费久久精品99久久| 国产高清国内精品福利99久久| 亚洲国产成人精品女人久久久 | 97久久精品无码一区二区| 波多野结衣久久一区二区| 99久久国产综合精品网成人影院| 99久久国产精品免费一区二区| 午夜久久久久久禁播电影| 久久不见久久见免费视频7| 国产麻豆精品久久一二三| 久久福利资源国产精品999| 久久人妻少妇嫩草AV无码蜜桃| 国产精品久久久久国产A级| 99久久无色码中文字幕人妻| 亚洲精品成人久久久| 91久久精品国产成人久久| 一级做a爰片久久毛片16| 久久久久久a亚洲欧洲aⅴ| A狠狠久久蜜臀婷色中文网| 久久大香香蕉国产|