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

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

            Section 3.3 - Shopping Offers

            Posted on 2009-06-03 10:17 superman 閱讀(252) 評(píng)論(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 
            久久综合久久综合九色| 精品国产乱码久久久久软件| 国产成人久久精品区一区二区| 久久久久久亚洲精品成人| 久久99热国产这有精品| 亚洲国产精品无码久久九九| 日韩av无码久久精品免费| 999久久久国产精品| 色8久久人人97超碰香蕉987| 99久久99久久精品国产片果冻 | 日本免费一区二区久久人人澡| 久久久久久国产精品无码下载| 精品久久久无码人妻中文字幕| 久久九九有精品国产23百花影院| 中文字幕亚洲综合久久菠萝蜜| 成人国内精品久久久久影院| 久久99热这里只有精品66| 9191精品国产免费久久| 久久精品国产亚洲av麻豆色欲| 久久本道久久综合伊人| 久久国产精品一区二区| 国内精品伊人久久久久av一坑 | 精品一二三区久久aaa片| 91精品国产色综久久| 99久久无色码中文字幕| 久久超乳爆乳中文字幕| 国产亚洲美女精品久久久2020| 久久婷婷色综合一区二区| 久久精品18| 精品久久久久国产免费| 精品无码久久久久久久久久| 亚洲国产成人久久综合一 | 国产高潮国产高潮久久久| 久久午夜羞羞影院免费观看| 亚洲综合日韩久久成人AV| 亚洲中文字幕久久精品无码APP| 97视频久久久| 婷婷五月深深久久精品| 久久无码人妻一区二区三区午夜 | 欧美精品国产综合久久| 久久久SS麻豆欧美国产日韩|