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

            A Za, A Za, Fighting...

            堅(jiān)信:勤能補(bǔ)拙

            USACO Packing Rectangles

            問題:
            http://ace.delos.com/usacoprob2?a=CTINrbaHwEW&S=packrec

            思路:
            這題不會(huì),考慮的時(shí)候以為任意兩個(gè)矩陣至少存在相同的邊才可以合并...結(jié)果完全錯(cuò)誤

            參考:
            http://starforever.blog.hexun.com/2097115_d.html
            http://greenmoon55.com/usaco-packing-rectangles/

            另外,這題學(xué)會(huì)了在C里面使用bool類型,原來不知道呢(*^__^*) 嘻嘻……
            stdbool.h頭文件

            代碼:
              1 /*
              2 ID: simplyz2
              3 LANG: C
              4 TASK: packrec
              5 */
              6 #include<stdio.h>
              7 #include<stdbool.h>
              8 #include<stdlib.h>
              9 #include<string.h>
             10 #define MAX_NUM 5
             11 #define INF 0x7FFFFFFF
             12 #define Max(a, b) ((a)>(b) ? (a) : (b))
             13 struct Rec {
             14     int h, w;
             15 } rectangle[MAX_NUM], rect[MAX_NUM], ans[MAX_NUM];
             16 bool used[MAX_NUM];
             17 int w, h, total, area;
             18 
             19 void
             20 exchange(struct Rec *r)
             21 {
             22     int temp = r->h;
             23     r->= r->w;
             24     r->= temp;
             25 }
             26 
             27 void
             28 judge()
             29 {
             30     int i, j, temp;
             31     if(w > h) {
             32         temp = w;
             33         w = h;
             34         h = temp;
             35     }
             36     if(w*<= area) {
             37         if(w*== area) {
             38             for(i=1; i<total; i++)
             39                 if(ans[i].w == w)
             40                     return;
             41             for(i=1; i<total; i++)
             42                 if(ans[i].w > w) {
             43                     for(j=total; j>i; j--)
             44                         ans[j] = ans[j-1];
             45                     ans[i].w = w;
             46                     ans[i].h = h;
             47                     ++total;
             48                     return;
             49                 }
             50             ans[total].w = w;
             51             ans[total++].h = h;
             52         } else {
             53             area = w*h;
             54             total = 1;
             55             ans[total].w = w;
             56             ans[total].h = h;
             57         }
             58     }
             59 }
             60 
             61 void
             62 work()
             63 {   
             64     //Case 1
             65     w=rect[1].w+rect[2].w+rect[3].w+rect[4].w;
             66     h=Max(rect[1].h,rect[2].h);
             67     h=Max(h,rect[3].h);
             68     h=Max(h,rect[4].h);
             69     judge();
             70  
             71     //Case 2
             72     w=Max(rect[1].w+rect[2].w+rect[3].w,rect[4].w);
             73     h=Max(rect[1].h,rect[2].h);
             74     h=Max(h,rect[3].h);
             75     h+=rect[4].h;
             76     judge();
             77  
             78     //Case 3
             79     w=Max(rect[1].w+rect[2].w,rect[3].w)+rect[4].w;
             80     h=Max(Max(rect[1].h,rect[2].h)+rect[3].h,rect[4].h);
             81     judge();
             82  
             83     //Case 4
             84     w=rect[1].w+Max(rect[2].w,rect[3].w)+rect[4].w;
             85     h=Max(rect[1].h,rect[4].h);
             86     h=Max(h,rect[2].h+rect[3].h);
             87     judge();
             88  
             89     //Case 6
             90     if (rect[3].h>=rect[2].h+rect[4].h)
             91     {
             92         w=Max(rect[3].w+rect[2].w,rect[3].w+rect[4].w);
             93         w=Max(w,rect[1].w);
             94         h=rect[1].h+rect[3].h;
             95         judge();
             96         return;
             97     }
             98     if (rect[3].h>rect[4].h)
             99     {
            100         w=Max(rect[1].w+rect[2].w,rect[2].w+rect[3].w);
            101         w=Max(w,rect[4].w+rect[3].w); 
            102         h=Max(rect[1].h+rect[3].h,rect[2].h+rect[4].h);
            103         judge();
            104         return;
            105     }
            106     if (rect[3].h==rect[4].h)
            107     {
            108         w=Max(rect[1].w+rect[2].w,rect[3].w+rect[4].w);
            109         h=Max(rect[1].h,rect[2].h)+rect[3].h;
            110         judge();
            111         return;
            112     }
            113     if (rect[3].h<rect[4].h && rect[4].h<rect[3].h+rect[1].h)
            114     {
            115         w=Max(rect[1].w+rect[2].w,rect[1].w+rect[4].w);
            116         w=Max(w,rect[3].w+rect[4].w);
            117         h=Max(rect[1].h+rect[3].h,rect[2].h+rect[4].h);
            118         judge();
            119         return;
            120     }
            121     w=Max(rect[2].w,rect[1].w+rect[4].w);
            122     w=Max(w,rect[3].w+rect[4].w);
            123     h=rect[4].h+rect[2].h;
            124     judge(); 
            125 }
            126 
            127 void
            128 rotate(int depth)
            129 {
            130     if(depth == MAX_NUM) {
            131         work();
            132         return;
            133     }
            134     rotate(depth+1);
            135     exchange(rect+depth);
            136     rotate(depth+1);
            137 }
            138 
            139 void
            140 dfs(int depth)
            141 {
            142     int i;
            143     if(depth == MAX_NUM) {
            144         rotate(1);
            145         return;
            146     }
            147     for(i=1; i<MAX_NUM; i++) {
            148         if(!used[i]) {
            149             used[i] = true;
            150             rect[depth] = rectangle[i];
            151             dfs(depth+1);
            152             used[i] = false;
            153         }
            154     }
            155 }
            156 
            157 int
            158 main(int argc, char **argv)
            159 {
            160     int i;
            161     freopen("packrec.in""r", stdin);
            162     freopen("packrec.out""w", stdout);
            163     for(i=1; i<MAX_NUM; i++)
            164         scanf("%d %d"&rectangle[i].w, &rectangle[i].h);
            165     total = 1;
            166     area = INF;
            167     memset(used, 0sizeof(used));
            168     dfs(1);
            169     printf("%d\n", area);
            170     for(i=1; i<total; i++)
            171         printf("%d %d\n", ans[i].w, ans[i].h);
            172     return 0;
            173 }

            posted on 2010-10-13 19:45 simplyzhao 閱讀(387) 評(píng)論(0)  編輯 收藏 引用 所屬分類: B_搜索

            導(dǎo)航

            <2010年9月>
            2930311234
            567891011
            12131415161718
            19202122232425
            262728293012
            3456789

            統(tǒng)計(jì)

            常用鏈接

            留言簿(1)

            隨筆分類

            隨筆檔案

            搜索

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

            99精品国产免费久久久久久下载 | 久久精品国产清高在天天线| 精品久久久久成人码免费动漫| 色综合久久88色综合天天 | 久久影院亚洲一区| 精品国产乱码久久久久软件| 无码人妻久久一区二区三区免费丨| 欧美丰满熟妇BBB久久久| 日韩精品久久久久久| 国产精品久久久久久久午夜片| 日本高清无卡码一区二区久久| 亚洲精品无码久久久久| 国产AV影片久久久久久| 亚洲国产日韩欧美久久| 精品久久久久久国产潘金莲 | 久久电影网| 久久精品人人做人人爽97| 蜜臀久久99精品久久久久久| 狠狠色噜噜狠狠狠狠狠色综合久久| 人人狠狠综合88综合久久| 久久99国产精品久久99| 一本久久a久久精品亚洲| 久久99久久成人免费播放| 久久精品无码午夜福利理论片| 人妻丰满?V无码久久不卡| 91精品国产色综久久| 国产精品久久久久影院色| 一本一道久久综合狠狠老| 久久久久亚洲精品中文字幕 | 亚洲女久久久噜噜噜熟女| 综合人妻久久一区二区精品| 狠狠色丁香久久婷婷综合蜜芽五月| 久久综合欧美成人| 狠狠色丁香婷婷综合久久来| 久久精品国产99国产电影网| 精品国产乱码久久久久久郑州公司| 亚洲中文字幕久久精品无码APP | 久久精品夜夜夜夜夜久久| 国产精品18久久久久久vr| 久久综合久久综合久久| 国产精品久久久久影院嫩草|