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

USACO Section 3.2 Feed Ratios

Feed Ratios

1998 ACM Finals, Dan Adkins

Farmer John feeds his cows only the finest mixture of cow food, which has three components: Barley, Oats, and Wheat. While he knows the precise mixture of these easily mixable grains, he can not buy that mixture! He buys three other mixtures of the three grains and then combines them to form the perfect mixture.

Given a set of integer ratios barley:oats:wheat, find a way to combine them IN INTEGER MULTIPLES to form a mix with some goal ratio x:y:z.

For example, given the goal 3:4:5 and the ratios of three mixtures:

1:2:3
3:7:1
2:1:2
your program should find some minimum number of integer units (the `mixture') of the first, second, and third mixture that should be mixed together to achieve the goal ratio or print `NONE'. `Minimum number' means the sum of the three non-negative mixture integers is minimized.

For this example, you can combine eight units of mixture 1, one unit of mixture 2, and five units of mixture 3 to get seven units of the goal ratio:

    8*(1:2:3) + 1*(3:7:1) + 5*(2:1:2) = (21:28:35) = 7*(3:4:5)

Integers in the goal ratio and mixture ratios are all non-negative and smaller than 100 in magnitude. The number of units of each type of feed in the mixture must be less than 100. The mixture ratios are not linear combinations of each other.

PROGRAM NAME: ratios

INPUT FORMAT

Line 1: Three space separated integers that represent the goal ratios
Line 2..4: Each contain three space separated integers that represent the ratios of the three mixtures purchased.

SAMPLE INPUT (file ratios.in)

3 4 5
1 2 3
3 7 1
2 1 2

OUTPUT FORMAT

The output file should contain one line containing four integers or the word `NONE'. The first three integers should represent the number of units of each mixture to use to obtain the goal ratio. The fourth number should be the multiple of the goal ratio obtained by mixing the initial feed using the first three integers as mixing ratios.

SAMPLE OUTPUT (file ratios.out)

8 1 5 7

Analysis

This problem seems to be a deoth search problem, which, as a matter of fact, is truly a mathematical problem. This problem can be represented in forms of matrix multiply or a linear equation set.

Initially, the first line is saved in an array called b[MAX](MAX here is 3, but generally, we can deal with more complicated situations in this way by change the value of MAX).

What the next MAX lines can do is also and may function better with a MAX-level matrix A[MAX][MAX](squred). Firstly, turn the description into equations:

\large \left\{\begin{matrix}
a_{00}x_{0}+a_{01}x_{1}+a_{02}x_{2}=b_{0}\\ 
a_{10}x_{0}+a_{11}x_{1}+a_{12}x_{2}=b_{1}\\ 
a_{20}x_{0}+a_{21}x_{1}+a_{22}x_{2}=b_{2}
\end{matrix}\right.
Later, using matrix to translate it:
 
\large \begin{pmatrix}
a_{00} & a_{01} & a_{02}\\ 
a_{10} & a_{11} & a_{12}\\ 
a_{20} & a_{21} & a_{22}
\end{pmatrix}.\begin{pmatrix}
x_{0}\\ 
x_{1}\\ 
x_{2}
\end{pmatrix}=\begin{pmatrix}
b_{0}\\ 
b_{1}\\ 
b_{2}
\end{pmatrix}
It is obvious to find the solution of the equation set by Cramer Law. But I nearly forget to tell you another important thing, which is as important as the mathematical method, is that if det(A) is 0 and not all of the elements in b[MAX] are 0, then the answer is NONE. What's more, as a practical problem, it is unbelievable to find the answer which is negative. Both are the edges to determine whether the answer is avaliable.

After this, you may be interested in find det(A), and I will describe it in another post.

Code
/*
ID:braytay1
PROG:ratios
LANG:C++
*/

#include 
<iostream>
#include 
<cmath>
#include 
<fstream>
#define MAX 3
#define eps 0.000001
using namespace std;

int det(int a[MAX][MAX]){
    
double s=1;
    
double tmp[MAX][MAX];
    
for (int i=0;i<MAX;i++){
        
for (int j=0;j<MAX;j++){
            tmp[i][j]
=double(a[i][j]);
        }

    }

    
for (int k=0;k<MAX-1;k++){
        
for (int i=k+1;i<MAX;i++){        
            
for (int j=k+1;j<MAX;j++){
                tmp[i][j]
-=tmp[i][k]*tmp[k][j]/tmp[k][k];
            }

        }

    }

    
for (int i=0;i<MAX;i++)
        s
*=tmp[i][i];
    
int res;
    res
=int(s);
    
if (fabs(s-res)<eps) return res;
    
else {
        
if (res>0return res+1;
        
else return res-1;
    }

}

int sp_gcd(int a,int b){
    a
=abs(a);
    b
=abs(b);
    
if (a<b) return a==0?b:sp_gcd(b%a,a);
    
else return b==0?a:sp_gcd(b,a%b);
}


int gcd(int a[MAX],int s){
    
int res;
    res
=sp_gcd(a[0],a[1]);
    
for (int i=2;i<MAX;i++){
        res
=sp_gcd(res,a[i]);
    }

    res
=sp_gcd(res,s);
    
return res;
}

int main(){
    ifstream fin(
"ratios.in");
    ofstream fout(
"ratios.out");
    
int A[MAX][MAX],b[MAX],x[MAX];
    
int k,flag_s=0;
    
for (int i=0;i<MAX;i++){
        fin
>>b[i];
        
if (b[i]) flag_s=1;
    }

    
for (int i=0;i<MAX;i++)
        
for (int j=0;j<MAX;j++) fin>>A[j][i];
    k
=det(A);
    
if (k==0&&flag_s) cout<<"NONE"<<endl;
    
else {
        
int k_sign;
        
if (k>0) k_sign=1;
        
else if (k==0) k_sign=0;
        
else k_sign=-1;
        
for (int i=0;i<MAX;i++){
            
int A_tmp[MAX][MAX];
            
for (int i1=0;i1<MAX;i1++){
                
for (int j1=0;j1<MAX;j1++){
                    
if (j1==i) A_tmp[i1][j1]=b[i1];
                    
else A_tmp[i1][j1]=A[i1][j1];
                }

            }

            x[i]
=det(A_tmp);
        }


        
int div;
        div
=gcd(x,k);
        
for (int i=0;i<MAX;i++){
            
if (x[i]*k_sign<0{
                fout
<<"NONE"<<endl;
                
return 0;
            }

        }

        
for (int i=0;i<MAX;i++){
            x[i]
=x[i]/div*k_sign;
            fout
<<x[i]<<" ";
        }

        k
=k/div*k_sign;
        fout
<<k<<endl;
    }

    
return 0;
}

posted on 2008-08-26 00:46 幻浪天空領主 閱讀(403) 評論(0)  編輯 收藏 引用 所屬分類: USACO

<2025年9月>
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

導航

統計

常用鏈接

留言簿(1)

隨筆檔案(2)

文章分類(23)

文章檔案(22)

搜索

最新評論

閱讀排行榜

評論排行榜

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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| 亚洲欧美中日韩| 欧美日韩另类字幕中文| 免费一级欧美在线大片| 久久综合福利| 日韩一级黄色片| 一区二区黄色| 亚洲永久网站| 老司机免费视频一区二区三区 | 一本一道久久综合狠狠老精东影业| 日韩视频免费观看| 亚洲欧美日韩另类| 另类激情亚洲| 久久综合给合久久狠狠狠97色69| 亚洲午夜精品视频| 久久久久久久一区二区| 欧美福利一区二区| 亚洲视频网在线直播| 久久国产高清| 国产精品高潮呻吟久久av黑人| 国产亚洲电影| 99国产精品自拍| 久久精品视频免费| 亚洲精品视频免费观看| 欧美一区二区在线看| 欧美精品激情在线| 国模套图日韩精品一区二区| 夜夜夜久久久| 欧美丰满高潮xxxx喷水动漫| 亚洲欧美日韩国产综合精品二区| 欧美国产视频一区二区| 国产欧美日韩亚州综合| 一区二区三区欧美成人| 嫩草伊人久久精品少妇av杨幂| 在线视频一区观看| 欧美另类videos死尸| 在线观看91久久久久久| 午夜在线播放视频欧美| 日韩视频不卡中文| 欧美va亚洲va国产综合| 国际精品欧美精品| 欧美一级淫片aaaaaaa视频| 亚洲乱码一区二区| 欧美欧美午夜aⅴ在线观看| 久久精品国产99| 亚洲精品日本| 老**午夜毛片一区二区三区| 午夜精品福利在线观看| 欧美日韩国产黄| 亚洲日韩欧美视频| 免费看亚洲片| 久久精品国产999大香线蕉| 欧美色图一区二区三区| 日韩一级欧洲| 日韩午夜激情| 国产精品成人一区二区网站软件 | 国产精品国色综合久久| 亚洲精品黄网在线观看| 欧美高清视频在线| 蜜臀av一级做a爰片久久| 伊人久久成人| 美日韩丰满少妇在线观看| 欧美伊人久久久久久午夜久久久久| 国产精品成人av性教育| 一区二区三区视频在线| 日韩亚洲在线观看| 国产精品久久久久久福利一牛影视| 亚洲午夜精品久久久久久app| 宅男噜噜噜66国产日韩在线观看| 国产精品高潮呻吟| 久久久99国产精品免费| 久久躁日日躁aaaaxxxx| 亚洲毛片视频| 欧美日本中文字幕| 最近中文字幕日韩精品| 日韩手机在线导航| 国产精品一级久久久| 久久久综合香蕉尹人综合网| 久久亚洲精品网站| 亚洲深夜福利网站| 午夜综合激情| 亚洲三级视频| 午夜电影亚洲| 伊人春色精品| 亚洲精品久久久久久久久| 欧美成人69| 欧美一区二区三区日韩| 久久久最新网址| 欧美日韩在线播| 久久精品在线| 欧美精品videossex性护士| 亚洲欧美日韩在线高清直播| 欧美在线免费播放| 日韩网站免费观看| 欧美在线不卡视频| 亚洲深夜福利视频| 麻豆精品在线视频| 欧美日韩一区三区四区| 国产一区二区三区高清| 亚洲动漫精品| 国产精品亚发布| 欧美二区在线观看| 国产日韩综合一区二区性色av| 亚洲第一在线综合网站| 欧美尤物一区| 99精品国产在热久久婷婷| 一本大道av伊人久久综合| 久久深夜福利免费观看| 国产精品美女久久| 亚洲激情自拍| 国产麻豆综合| 欧美精品亚洲| 欧美日产在线观看| 香蕉成人啪国产精品视频综合网| 亚洲尤物在线| 亚洲深夜福利在线| 欧美视频日韩| 亚洲一级在线| 亚洲欧美日韩精品久久久| 欧美成人高清| 久色成人在线| 欧美精品三级| 欧美激情第六页| 亚洲青涩在线| 欧美日韩一区不卡| 亚洲一区二区三区免费视频| 国产欧美日韩一区二区三区| 亚洲精品久久久久久久久| 亚洲美女在线观看| 欧美有码在线观看视频| 久久久久久国产精品一区| 1000部国产精品成人观看| 99re这里只有精品6| 亚洲人成网站色ww在线| 国产精品久久久久久久久久妞妞| 99精品热视频| 国产资源精品在线观看| 性色av一区二区三区| 99国产麻豆精品| 国产精品三级视频| 亚洲国产1区| 亚洲男人的天堂在线观看| 蜜臀av性久久久久蜜臀aⅴ四虎 | 久久国产欧美| 午夜精品视频在线| 欧美午夜不卡影院在线观看完整版免费 | 欧美大片免费观看| 久久综合亚州| 狠狠色丁香婷综合久久| 欧美一区二区私人影院日本| 亚洲东热激情| 亚洲高清成人| 欧美激情中文字幕乱码免费| 亚洲欧洲在线免费| 午夜精品一区二区三区电影天堂 | 亚洲人成毛片在线播放| 欧美大片网址| 99这里只有久久精品视频| 午夜精品免费视频| 曰本成人黄色| 国产精品国产三级国产aⅴ无密码| 亚洲在线观看视频网站| 久久在线免费观看视频| 亚洲免费久久| 国产一区二区三区电影在线观看| 免费视频亚洲| 亚洲午夜久久久| 美日韩免费视频| 亚洲香蕉在线观看| 久久综合中文| 99pao成人国产永久免费视频| 久久精品国产77777蜜臀| 91久久久亚洲精品| 国产伦精品一区二区三区| 久久综合九色综合久99| 亚洲精品一区二区三区四区高清| 欧美一区2区三区4区公司二百| 亚洲国产精品t66y| 国产麻豆91精品| 亚洲国产精品激情在线观看| 欧美日韩亚洲综合在线| 欧美在线观看一区| 亚洲精品久久久久久久久久久久 | 性欧美办公室18xxxxhd| 久久婷婷av| 欧美激情精品久久久久久免费印度| 亚洲网站在线| 亚洲人成网站777色婷婷| 久久精品99无色码中文字幕| 日韩视频中午一区| 一区二区在线视频观看| 国产精品资源| 国产精品久久久久久久久久直播| 欧美国产日韩在线| 牛牛精品成人免费视频| 久久久www成人免费无遮挡大片| 中国成人在线视频| 亚洲精品免费在线| 一区二区高清在线| 91久久中文字幕|