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

superman

聚精會(huì)神搞建設(shè) 一心一意謀發(fā)展
posts - 190, comments - 17, trackbacks - 0, articles - 0
   :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

Section 1.4 - Packing Rectangles

Posted on 2009-03-19 16:35 superman 閱讀(338) 評(píng)論(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>
            国产精品高清在线| 欧美一区二区三区精品| 午夜久久影院| 欧美在线免费| 久久久久成人精品| 欧美黄色小视频| 日韩视频中文字幕| 亚洲欧美精品伊人久久| 久久婷婷国产综合精品青草| 欧美高清视频在线播放| 欧美午夜视频在线| 一色屋精品视频在线看| 99精品视频免费观看视频| 亚洲男女自偷自拍| 另类av一区二区| 亚洲欧洲视频| 亚洲欧美综合精品久久成人| 久久久久久久综合色一本| 欧美日本中文字幕| 国产一区二区三区在线观看视频| 亚洲国产精品专区久久| 亚洲嫩草精品久久| 欧美激情一区二区三区在线 | 亚洲国产精品久久| 在线综合视频| 模特精品在线| 国产欧美一区二区精品忘忧草| 亚洲人成网站在线播| 欧美一区视频在线| 亚洲三级视频在线观看| 久久久精品久久久久| 国产精品免费观看在线| 亚洲人成在线观看网站高清| 亚洲欧美中文另类| 亚洲国产一区二区三区a毛片| 午夜精品一区二区三区在线| 欧美韩日一区二区| 激情综合电影网| 性做久久久久久久久| 亚洲欧洲精品一区二区三区| 久久成年人视频| 欧美日韩国内自拍| 亚洲欧洲日韩综合二区| 麻豆91精品| 久久精品日韩| 国产一区二区毛片| 午夜在线电影亚洲一区| 夜夜嗨av一区二区三区免费区| 欧美91大片| 亚洲国产欧美久久| 你懂的视频欧美| 久久久久久夜精品精品免费| 国产一区二区高清不卡| 欧美专区在线| 亚洲欧美日本日韩| 欧美日韩ab片| 久久久之久亚州精品露出| 亚洲图片在线| 国产精品久久久久99| 亚洲网站视频| 99人久久精品视频最新地址| 欧美日韩国产不卡| 一区二区三区日韩欧美| 亚洲精品一级| 国产精品成人免费| 亚洲欧美另类久久久精品2019| 一本色道久久| 国产精品久久久久久久久久久久 | 国产伦精品一区二区三区在线观看 | 亚洲精品麻豆| 91久久国产自产拍夜夜嗨| 欧美国产精品久久| 亚洲最新色图| 亚洲无人区一区| 国产毛片精品国产一区二区三区| 欧美一区二区成人6969| 久久精品国产免费| 亚洲三级毛片| 一区二区久久| 国产一区二区三区在线观看网站| 蜜桃精品久久久久久久免费影院| 免费在线亚洲| 亚洲影院一区| 久久久精品动漫| 99精品国产福利在线观看免费 | 韩国免费一区| 亚洲欧洲在线看| 国产精品二区三区四区| 久久久综合免费视频| 欧美精品三级| 欧美伊人久久久久久午夜久久久久 | 男女激情视频一区| 亚洲永久免费av| 久久久www成人免费无遮挡大片| 亚洲国产综合视频在线观看| 一区二区高清在线观看| 激情欧美一区二区三区| 99国内精品| 亚洲国产精品久久| 亚洲性图久久| 亚洲狼人精品一区二区三区| 中日韩视频在线观看| 新67194成人永久网站| 亚洲尤物视频网| 在线精品观看| 欧美一区二区视频在线观看2020| 国产在线日韩| 亚洲日韩欧美视频一区| 国产一区二区精品| 99国产一区| 亚洲黄网站在线观看| 亚洲欧美日韩国产中文| 在线一区二区日韩| 美女在线一区二区| 久久久久国产精品www| 欧美午夜视频网站| 亚洲国产成人精品久久久国产成人一区| 国产精品久久久久久五月尺| 欧美a级大片| 国产一区二区成人| 亚洲一区二区三区四区五区午夜| 亚洲伦理中文字幕| 久久久精彩视频| 久久久水蜜桃av免费网站| 国产精品亚洲人在线观看| 亚洲精品乱码久久久久| 亚洲黄色片网站| 久久综合九九| 男女激情久久| 在线观看亚洲一区| 久久久之久亚州精品露出| 欧美一区精品| 国产精品伦理| 亚洲一区自拍| 欧美制服丝袜第一页| 国产精品欧美一区二区三区奶水| av成人激情| 亚洲欧美日韩精品综合在线观看| 欧美日韩综合不卡| 99精品欧美一区| 亚洲一区激情| 国产精品视频九色porn| 亚洲欧美日韩在线高清直播| 亚洲欧美日韩一区二区三区在线观看| 欧美午夜精品久久久久久久| 99视频日韩| 亚洲欧洲av一区二区三区久久| 国产精品高潮呻吟久久| 正在播放欧美一区| 久久九九国产| 在线成人国产| 欧美激情一区二区三级高清视频| 亚洲人成免费| 亚洲男人天堂2024| 国产亚洲欧美日韩精品| 久久九九免费视频| 欧美高清视频在线观看| 一区二区久久久久| 国产精品永久免费视频| 久久久91精品| 亚洲美女黄网| 久久久久久九九九九| 亚洲激情视频| 国产精品高潮粉嫩av| 久久精品首页| 亚洲乱码一区二区| 久久国产直播| 亚洲无限av看| 久久亚洲综合| 欧美成人69av| 亚洲婷婷在线| 蜜臀久久99精品久久久久久9| 日韩视频永久免费| 国产精品男人爽免费视频1| 久久另类ts人妖一区二区| 亚洲日韩第九十九页| 久久精品免费观看| 亚洲精品国产视频| 国产精品一区三区| 欧美黄污视频| 欧美一区91| 亚洲精选中文字幕| 美女999久久久精品视频| 亚洲一区二区三区视频播放| 国产真实久久| 欧美性色aⅴ视频一区日韩精品| 欧美在线观看一区| 一区二区三区 在线观看视| 久热精品视频| 欧美在线视频免费| 一区二区三区www| 国产中文一区二区三区| 欧美日韩国产影片| 女同性一区二区三区人了人一| 亚洲影院在线观看| 日韩亚洲一区二区| 亚洲精品黄色| 亚洲第一免费播放区| 狼人天天伊人久久| 久久久久久夜精品精品免费|