• <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.2 - Feed Ratios

            Posted on 2009-05-16 12:08 superman 閱讀(281) 評論(0)  編輯 收藏 引用 所屬分類: USACO
              1 #include <iostream>
              2 
              3 using namespace std;
              4 
              5 int gcd(const int a, const int b)
              6 {
              7     if (b == 0)
              8         return a;
              9     return gcd(b, a % b);
             10 }
             11 
             12 class Faction
             13 {
             14 private:
             15     int fz, fm;
             16 
             17 public:
             18     void to_proper_faction()
             19     {
             20         int t;
             21         while ((t = gcd(fz, fm)) != 1)
             22             fz /= t, fm /= t;
             23     }
             24 
             25     Faction() { fz = 1, fm = 0; }
             26     Faction(const int n) { fz = n, fm = 1; }
             27     Faction(const int a, const int b) { fz = a, fm = b; to_proper_faction(); }
             28 
             29     int getfz() { return fz; }
             30 
             31     bool isInteger() { return fm == 1; }
             32     bool isNegative() { return fz < 0 || fm < 0; }
             33 
             34     //======================================================
             35     Faction operator + (const Faction &b)
             36     {
             37         int t = fm * b.fm;
             38         Faction c(t / fm * fz + t / b.fm * b.fz, t);
             39         return c;
             40     }
             41     Faction operator - (const Faction &b)
             42     {
             43         int t = fm * b.fm;
             44         Faction c(t / fm * fz - t / b.fm * b.fz, t);
             45         return c;
             46     }
             47     Faction operator * (const Faction &b)
             48     {
             49         Faction c(fz * b.fz, fm * b.fm);
             50         return c;
             51     }
             52     Faction operator / (const Faction &b)
             53     {
             54         Faction c(fz * b.fm, fm * b.fz);
             55         return c;
             56     }
             57     //======================================================
             58     Faction operator + (const int n) { return *this + Faction(n); }
             59     Faction operator - (const int n) { return *this - Faction(n); }
             60     Faction operator * (const int n) { return *this * Faction(n); }
             61     Faction operator / (const int n) { return *this / Faction(n); }
             62 
             63     //======================================================
             64     void operator += (const Faction &b) { *this = *this + b; }
             65     void operator -= (const Faction &b) { *this = *this - b; }
             66     void operator *= (const Faction &b) { *this = *this * b; }
             67     void operator /= (const Faction &b) { *this = *this / b; }
             68 
             69     //======================================================
             70     friend std::istream& operator >> (std::istream &is, Faction &b)
             71     {
             72         is >> b.fz >> b.fm;
             73         return is;
             74     }
             75     friend std::ostream& operator << (std::ostream &os, const Faction &b)
             76     {
             77         if (b.fm == 1)
             78             os << b.fz;
             79         else
             80             os << b.fz << '/' << b.fm;
             81         return os;
             82     }
             83 }   ;
             84 
             85 int main()
             86 {
             87     freopen("ratios.in""r", stdin);
             88     freopen("ratios.out""w", stdout);
             89 
             90     int n = 3;
             91     Faction o[10][10], a[10][10], b[10], x[10];
             92 
             93     int t;
             94     for (int i = 0; i < n; i++)
             95     {
             96         cin >> t;
             97         b[i] = t;
             98     }
             99     for (int i = 0; i < n; i++)
            100     for (int j = 0; j < n; j++)
            101     {
            102         cin >> t;
            103         o[j][i] = t;
            104     }
            105 
            106     for (int p = 7; p < 100; p++)
            107     {
            108         for (int i = 0; i < n; i++)
            109         for (int j = 0; j < n; j++)
            110             a[i][j] = o[i][j];
            111 
            112         for (int i = 0; i < n; i++)
            113             a[i][n] = b[i] * p;
            114 
            115         for (int i = 0; i < n - 1; i++)
            116             for (int j = i + 1; j < n; j++)
            117             {
            118                 Faction t = a[j][i] / a[i][i];
            119                 for (int k = 0; k <= n; k++)
            120                     a[j][k] -= t * a[i][k];
            121             }
            122         //====================================
            123         x[n - 1= a[n - 1][n] / a[n - 1][n - 1];
            124         for (int i = n - 2; i >= 0; i--)
            125         {
            126             x[i] = a[i][n];
            127             for (int j = i + 1; j < n; j++)
            128                 x[i] -= a[i][j] * x[j];
            129             x[i] /= a[i][i];
            130         }
            131 
            132         int i;
            133         for (i = 0; i < n; i++)
            134             if (x[i].isNegative() || x[i].isInteger() == false)
            135                 break;
            136         if (i == n)
            137         {
            138             x[n] = p;
            139 
            140             int tx[10], tg;
            141             for (int i = 0; i <= n; i++)
            142                 tx[i] = x[i].getfz();
            143             tg = tx[0];
            144             for (int i = 1; i <= n; i++)
            145                 tg = gcd(tg, tx[i]);
            146 
            147             if (tg != 1)
            148                 for (int i = 0; i <= n; i++)
            149                     tx[i] /= tg;
            150 
            151             for (int i = 0; i <= n; i++)
            152                 cout << tx[i] << (i == n ? '\n' : ' ');
            153 
            154             return 0;
            155         }
            156     }
            157 
            158     cout << "NONE" << endl;
            159 
            160     return 0;
            161 }
            162 
            国产69精品久久久久99尤物| 一级做a爰片久久毛片免费陪| 久久精品aⅴ无码中文字字幕重口| 国产福利电影一区二区三区,免费久久久久久久精 | 精品国产乱码久久久久软件| a级成人毛片久久| 久久精品国产亚洲77777| 久久亚洲日韩精品一区二区三区| 久久精品成人一区二区三区| 精品一区二区久久| 久久无码人妻一区二区三区| 日本人妻丰满熟妇久久久久久| 久久综合九色综合久99| 中文成人无码精品久久久不卡| 人妻精品久久久久中文字幕| 中文国产成人精品久久亚洲精品AⅤ无码精品 | 久久久久亚洲av无码专区喷水| 国产高清国内精品福利99久久| 国产人久久人人人人爽| 久久久精品免费国产四虎| 精品久久国产一区二区三区香蕉 | 国产精品成人久久久久久久| 久久人妻少妇嫩草AV蜜桃| 97久久婷婷五月综合色d啪蜜芽| 亚洲中文久久精品无码| 一本色道久久88加勒比—综合| 青青草国产精品久久久久| 日韩影院久久| 亚洲精品无码久久久久去q| 久久久久久久99精品免费观看| 色综合久久中文综合网| 久久精品国产99国产精品导航 | 久久久久久久亚洲Av无码| 国产精品久久久久久久午夜片 | 久久伊人五月天论坛| 久久99精品久久久久久久久久| Xx性欧美肥妇精品久久久久久| 婷婷久久精品国产| 久久国产乱子精品免费女| 久久精品国产色蜜蜜麻豆| 国产精品成人99久久久久|