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

            superman

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

            Section 3.3 - Shopping Offers

            Posted on 2009-06-03 10:17 superman 閱讀(248) 評論(0)  編輯 收藏 引用 所屬分類: USACO
              1 #include <set>
              2 #include <iostream>
              3 
              4 using namespace std;
              5 
              6 class SepcialOffer;
              7 class Cart;
              8 
              9 class SpecialOffer {
             10 private:
             11     int n;
             12     int c[5];   //code of each product
             13     int x[5];   //amount of each product needed
             14 public:
             15     int sp;     //special price
             16 public:
             17     friend class Cart;
             18     friend istream& operator>>(istream &is, SpecialOffer &t) {
             19         is >> t.n;
             20         for (int i = 0; i < t.n; i++)
             21             is >> t.c[i] >> t.x[i];
             22         is >> t.sp;
             23         return is;
             24     }
             25 }   so[100];    //special offers set
             26 
             27 class Cart {
             28 private:
             29     int n;
             30     int c[5];   //code of each product in the cart
             31     int x[5];   //amount of each product int the cart
             32     int p[5];   //the regular price of each product int the cart
             33 public:
             34     int bestp;  //the best price of all products int the cart
             35 public:
             36     int regularPrice() {
             37         int sum = 0;
             38         for (int i = 0; i < n; i++)
             39             sum += p[i] * x[i];
             40         return sum;
             41     }
             42     bool couldUseSpecialOffer(const SpecialOffer &t) const {
             43         for (int i = 0; i < t.n; i++) {
             44             int j;
             45             for (j = 0; j < n; j++)
             46                 if (t.c[i] == c[j] && t.x[i] <= x[j])
             47                     break;
             48             if (j == n)
             49                 return false;
             50         }
             51         return true;
             52     }
             53     Cart useSpecialOffer(const SpecialOffer &t) const {
             54         Cart nc = *this;
             55         for (int i = 0; i < t.n; i++) {
             56             int j;
             57             for (j = 0; j < n; j++)
             58                 if (t.c[i] == c[j] && t.x[i] <= x[j]) {
             59                     nc.x[j] -= t.x[i];
             60                     break;
             61                 }
             62         }
             63         return nc;
             64     }
             65     bool operator<(const Cart &t) const {
             66         for (int i = 0; i < n; i++)
             67             if (x[i] != t.x[i])
             68                 return x[i] - t.x[i] < 0 ? true : false;
             69         return false;
             70     }
             71     friend istream& operator>>(istream &is, Cart &t) {
             72         is >> t.n;
             73         for (int i = 0; i < t.n; i++)
             74             is >> t.c[i] >> t.x[i] >> t.p[i];
             75         return is;
             76     }
             77 }   cart;
             78 
             79 int so_num;   //special offers num
             80 set<Cart> cartSet;
             81 
             82 int search(Cart cart)
             83 {
             84     set<Cart>::iterator it = cartSet.find(cart);
             85     if (it != cartSet.end())
             86         return it->bestp;
             87 
             88 
             89     cart.bestp = INT_MAX;
             90     for (int i = 0; i < so_num; i++)
             91         if (cart.couldUseSpecialOffer(so[i]))
             92             cart.bestp <?= (search(cart.useSpecialOffer(so[i])) + so[i].sp);
             93 
             94     cart.bestp <?= cart.regularPrice();
             95 
             96     cartSet.insert(cart);
             97 
             98     return cart.bestp;
             99 }
            100 
            101 int main()
            102 {
            103     freopen("shopping.in""r", stdin);
            104     freopen("shopping.out""w", stdout);
            105 
            106     cin >> so_num;
            107     for (int i = 0; i < so_num; i++)
            108         cin >> so[i];
            109     cin >> cart;
            110 
            111     cout << search(cart) << endl;
            112 
            113     return 0;
            114 }
            115 
            亚洲一区中文字幕久久| 亚洲日本久久久午夜精品| 久久伊人五月天论坛| 久久精品中文无码资源站| 国产免费久久久久久无码| 国产69精品久久久久777| 亚洲AV无码久久寂寞少妇| 精品久久久久久国产| 久久精品夜夜夜夜夜久久| 久久国产亚洲精品麻豆| 久久99久久无码毛片一区二区| 久久精品国产精品亚洲艾草网美妙| 精品99久久aaa一级毛片| 久久国产午夜精品一区二区三区| 国内精品伊人久久久久影院对白| 伊人久久精品线影院| 久久亚洲国产欧洲精品一| 亚洲中文字幕无码久久2020 | 蜜桃麻豆www久久国产精品| 久久亚洲国产成人精品无码区| 久久免费99精品国产自在现线| 国产精品久久婷婷六月丁香| 无码人妻久久一区二区三区免费丨 | 国产成人精品综合久久久| 中文字幕无码免费久久| 久久亚洲高清观看| 青草国产精品久久久久久| 四虎影视久久久免费观看| 国产精品狼人久久久久影院| 无码人妻久久一区二区三区| 蜜桃麻豆WWW久久囤产精品| 久久精品国产黑森林| 99精品久久久久久久婷婷| 久久99毛片免费观看不卡| 久久综合88熟人妻| 久久丫精品国产亚洲av不卡 | 东京热TOKYO综合久久精品 | 久久男人AV资源网站| 亚洲国产天堂久久综合网站| 91麻豆国产精品91久久久| 久久精品国产免费观看三人同眠|