青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

superman

聚精會神搞建設 一心一意謀發展
posts - 190, comments - 17, trackbacks - 0, articles - 0
   :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

Section 1.4 - Packing Rectangles

Posted on 2009-03-19 16:35 superman 閱讀(338) 評論(0)  編輯 收藏 引用 所屬分類: USACO
  1 #include <iostream>
  2 
  3 using namespace std;
  4 
  5 int max(int a, int b, int c)
  6 {
  7     return max(max(a, b), c);
  8 }
  9 
 10 int max(int a, int b, int c, int d)
 11 {
 12     return max(max(a, b, c), d);
 13 }
 14 
 15 struct Rectangle
 16 {
 17     int h;  //height
 18     int w;  //width
 19 }   rect[4];
 20 
 21 int ans = 65535;
 22 int ans_cnt = 0;
 23 int ans_w[24], ans_h[24];
 24 
 25 void updateAns(int tot_w, int tot_h)
 26 {
 27     if (tot_w * tot_h <= ans)
 28     {
 29         if (tot_w * tot_h < ans)
 30         {
 31             ans = tot_w * tot_h;
 32             ans_cnt = 0;
 33         }
 34         for (int i = 0; i < ans_cnt; i++)
 35             if (ans_w[i] == min(tot_w, tot_h) && ans_h[i] == max(tot_w, tot_h))
 36                 return;
 37         ans_w[ans_cnt] = min(tot_w, tot_h);
 38         ans_h[ans_cnt] = max(tot_w, tot_h);
 39         ans_cnt++;
 40     }
 41 }
 42 
 43 void calcArea(int x[], int i)
 44 {
 45     int h0 = rect[x[0]].h; int w0 = rect[x[0]].w;
 46     int h1 = rect[x[1]].h; int w1 = rect[x[1]].w;
 47     int h2 = rect[x[2]].h; int w2 = rect[x[2]].w;
 48     int h3 = rect[x[3]].h; int w3 = rect[x[3]].w;
 49     if ((i & 1== 1) swap(h0, w0);
 50     if ((i & 2== 2) swap(h1, w1);
 51     if ((i & 4== 4) swap(h2, w2);
 52     if ((i & 8== 8) swap(h3, w3);
 53 
 54     int tot_w, tot_h;
 55 
 56     //1
 57     tot_h = max(h0, h1, h2, h3);
 58     tot_w = w0 + w1 + w2 + w3;
 59     updateAns(tot_w, tot_h);
 60     //2
 61     tot_h = max(h0, h1, h2) + h3;
 62     tot_w = max(w0 + w1 + w2, w3);
 63     updateAns(tot_w, tot_h);
 64     //3
 65     tot_h = max(max(h0, h1) + h3, h2);
 66     tot_w = max(w0 + w1, w3) + w2;
 67     updateAns(tot_w, tot_h);
 68     //4
 69     tot_h = max(h0 + h1, h2, h3);
 70     tot_w = max(w0, w1) + w2 + w3;
 71     updateAns(tot_w, tot_h);
 72     //5
 73     tot_h = max(h0 + h1, h2 + h3);
 74     tot_w = max(w0 + w3, w1 + w2);
 75     if (h0 + h2 > tot_h && w0 + w2 > tot_w) return;
 76     if (h1 + h3 > tot_h && w1 + w3 > tot_w) return;
 77     updateAns(tot_w, tot_h);
 78 }
 79 
 80 void getPermutation(int x[], int p)
 81 {
 82     if (p >= 4)
 83     {
 84         for (int i = 0; i <= 15; i++)
 85             calcArea(x, i);
 86         return;
 87     }
 88     for (int i = p; i < 4; i++)
 89     {
 90         swap(x[i], x[p]);
 91         getPermutation(x, p + 1);
 92         swap(x[i], x[p]);
 93     }
 94 }
 95 
 96 int main()
 97 {
 98     freopen("packrec.in""r", stdin);
 99     freopen("packrec.out""w", stdout);
100 
101     for (int i = 0; i < 4; i++)
102         cin >> rect[i].w >> rect[i].h;
103 
104     int x[4= { 0123 };  //the permutation of 4 rectangles
105 
106     getPermutation(x, 0);
107 
108     for (int i = 0; i < ans_cnt - 1; i++)
109         for (int j = i + 1; j < ans_cnt; j++)
110             if (ans_w[i] > ans_w[j])
111             {
112                 swap(ans_w[i], ans_w[j]);
113                 swap(ans_h[i], ans_h[j]);
114             }
115 
116     cout << ans << endl;
117     for (int i = 0; i < ans_cnt; i++)
118         cout << ans_w[i] << ' ' << ans_h[i] << endl;
119 
120     return 0;
121 }
122 
青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
            亚洲男人第一av网站| 国产精品99久久久久久白浆小说| 久久天天狠狠| 亚洲无玛一区| 亚洲毛片一区| 99精品视频免费观看| 国产一区二区三区高清在线观看 | 老鸭窝亚洲一区二区三区| 亚洲成色精品| 欧美~级网站不卡| 久久综合九色九九| 久久亚洲一区二区三区四区| 在线精品视频一区二区| 国产日韩欧美亚洲一区| 欧美日韩国产综合久久| 一区二区三区欧美在线观看| 亚洲五月六月| 亚洲视频网在线直播| 亚洲精品乱码| 亚洲永久精品国产| 久久久99国产精品免费| 久久精品中文字幕免费mv| 欧美一级专区| 欧美.日韩.国产.一区.二区| 一区二区av在线| 性xx色xx综合久久久xx| 久久精品视频在线看| 欧美sm视频| 韩国三级电影一区二区| 亚洲丰满少妇videoshd| 亚洲在线观看视频| 亚洲电影有码| 老色鬼精品视频在线观看播放| 欧美高清在线精品一区| 国产精品国产三级国产专区53| 国产精品久久久久久一区二区三区 | 欧美jizz19hd性欧美| 久久亚洲图片| 国产欧美一区二区三区久久人妖 | 亚洲精品一区二区三区福利| 亚洲第一页自拍| 开元免费观看欧美电视剧网站| 国产精品v欧美精品v日韩| 亚洲欧美色一区| 欧美极品影院| 亚洲午夜一区二区三区| 欧美成人有码| 猛男gaygay欧美视频| 国产精品一区二区久久精品| 国内成人精品2018免费看| 亚洲午夜一区二区| 欧美一区二区三区四区视频| 欧美黄色日本| 欧美一级艳片视频免费观看| 亚洲国产高清在线观看视频| 亚洲综合国产| 亚洲国产精品成人综合| 欧美激情久久久久| 国产精品色婷婷| 欧美一区日本一区韩国一区| 亚洲第一精品在线| 欧美日韩一区视频| 久久精品91久久久久久再现| 一本久道久久久| 欧美日韩精品久久| 欧美成人免费在线观看| 欧美日本免费一区二区三区| 在线播放中文字幕一区| 欧美激情一区二区三区在线| 欧美一区高清| 亚洲精品国产精品乱码不99| 久久青草久久| 久久久久一区| 久久一二三国产| 国产午夜精品久久久| 91久久精品国产91性色tv| 欧美日韩亚洲国产精品| 久久久久久网站| 亚洲视频一区在线| 亚洲国语精品自产拍在线观看| 在线一区二区三区做爰视频网站| 国模私拍一区二区三区| 亚洲无线一线二线三线区别av| 狠狠综合久久av一区二区小说| 亚洲日本中文字幕| 亚洲美女精品一区| 欧美日韩一区二区三区免费看| 免费观看久久久4p| 亚洲精品久久久蜜桃| 噜噜噜噜噜久久久久久91| 欧美一区2区三区4区公司二百| 免费观看在线综合| 一区二区三区毛片| 免费久久精品视频| 日韩视频在线一区二区三区| 欧美在线观看天堂一区二区三区| 午夜亚洲视频| 在线看片欧美| 国产精品女主播| 久久久亚洲人| 久久久国产精品一区二区三区| 一区二区三区欧美在线| 久久精品国产第一区二区三区最新章节| 欧美在线视频免费观看| 亚洲第一页在线| 国产精品自拍一区| 欧美日韩直播| 欧美日韩成人在线播放| 一区二区激情| 欧美在线免费一级片| 国产精品丝袜白浆摸在线| 久久综合久久久久88| 欧美成人黑人xx视频免费观看| 亚洲女女女同性video| 精品91视频| 国产精品欧美风情| 亚洲精品国产精品国自产在线| 在线综合亚洲| 亚洲人体大胆视频| 亚洲人体一区| 日韩午夜在线电影| 亚洲黄网站黄| 亚洲欧洲精品一区| 另类激情亚洲| 欧美成人一区二区在线| 久久精品国产亚洲一区二区| 国产欧美一区二区视频| 麻豆久久久9性大片| 中文在线不卡| 欧美一区二区三区视频在线观看| 亚洲国产另类久久久精品极度| 久久精品国产v日韩v亚洲 | 国产一区二区三区久久精品| 久久精品中文字幕免费mv| 亚洲欧美在线网| 欧美精品成人在线| 国产婷婷精品| 亚洲免费视频网站| 欧美国产综合| 亚洲综合欧美日韩| 麻豆乱码国产一区二区三区| 先锋资源久久| 欧美日韩亚洲一区在线观看| 欧美日本中文| 影院欧美亚洲| 久久国产精品亚洲va麻豆| 麻豆精品一区二区av白丝在线| 久久精品人人做人人爽电影蜜月| 欧美影院精品一区| 国产欧美日韩综合| 亚洲网站视频| 欧美大片在线观看一区| 亚洲图片在线观看| 久久午夜视频| 国产一区二区三区在线免费观看 | 久久婷婷av| 亚洲综合精品自拍| 亚洲韩国青草视频| 久久精品国产77777蜜臀| 久久精品国产99国产精品| 欧美大片在线观看一区| 亚洲国产高清视频| 久久精品亚洲| 国产在线视频欧美一区二区三区| 在线欧美一区| 美女爽到呻吟久久久久| 亚洲欧美精品suv| 国产精品美女在线| 欧美一级片一区| 久久夜色精品| 亚洲第一页在线| 最新精品在线| 激情综合视频| 亚洲精品日韩在线观看| 欧美高清不卡| 久久蜜臀精品av| 欧美劲爆第一页| 欧美成黄导航| 欧美视频在线播放| 久久久蜜桃精品| 国产精品久久国产愉拍 | 国产亚洲精品久久久久久| 午夜在线精品| 久久久久国色av免费看影院| 国产一区二区三区自拍| 久久久蜜桃一区二区人| 久久亚洲精品网站| 欧美在线地址| 国产女主播一区二区三区| 亚洲人成欧美中文字幕| 99热在线精品观看| 亚洲国产成人精品久久久国产成人一区| 亚洲精品日韩综合观看成人91| 国产欧美日韩亚州综合| 日韩一区二区高清| 好吊妞**欧美| 香蕉免费一区二区三区在线观看| 亚洲第一精品在线| 欧美成人一区在线| 欧美激情一区二区|