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

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 幻浪天空領主 閱讀(414) 評論(0)  編輯 收藏 引用 所屬分類: USACO

<2025年12月>
30123456
78910111213
14151617181920
21222324252627
28293031123
45678910

導航

統計

常用鏈接

留言簿(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无限| 国产日韩高清一区二区三区在线| 亚洲国产精品成人一区二区| 久久免费99精品久久久久久| 香蕉亚洲视频| 在线日韩中文字幕| 国产欧美一区二区三区久久人妖| 欧美亚洲系列| 久久激情网站| 亚洲人成网站在线播| 亚洲欧洲精品一区二区| 欧美黑人多人双交| 亚洲欧美不卡| 久久久人成影片一区二区三区| 亚洲区一区二区三区| 亚洲人成啪啪网站| 国产目拍亚洲精品99久久精品| 久久五月婷婷丁香社区| 欧美风情在线观看| 先锋影院在线亚洲| 久久网站热最新地址| 在线亚洲免费| 亚洲欧美美女| 久久九九电影| 亚洲免费在线观看| 久久免费偷拍视频| 亚洲午夜日本在线观看| 久久av老司机精品网站导航| 亚洲精品国产系列| 欧美亚洲色图校园春色| 亚洲精品免费网站| 午夜精品久久久久久久久久久久久| 在线观看视频欧美| 亚洲一区二区三区精品在线观看| 影音先锋中文字幕一区| 中文精品视频| 亚洲欧洲一区二区三区久久| 亚洲在线黄色| 一区二区三区欧美在线观看| 久久视频一区| 久久久国产精品一区| 欧美日韩一区二区三区高清| 美国成人直播| 国产女人18毛片水18精品| 亚洲人成人一区二区在线观看 | 亚洲精品视频在线看| 国产欧美69| 一本到高清视频免费精品| 在线免费观看日本一区| 亚洲综合二区| 亚洲午夜伦理| 欧美日韩人人澡狠狠躁视频| 亚洲第一区中文99精品| 国产综合视频| 欧美一区二区三区精品电影| 亚洲午夜视频在线| 欧美日韩成人一区二区三区| 欧美国产日韩一区| 在线日韩中文字幕| 久久精品夜色噜噜亚洲a∨| 午夜亚洲性色视频| 国产精品美女999| 99re66热这里只有精品3直播| 亚洲久久视频| 欧美激情精品久久久久久变态| 噜噜噜在线观看免费视频日韩| 国产午夜精品全部视频播放 | 欧美成人一区二区在线| 国产亚洲网站| 久久精品一区| 欧美波霸影院| 亚洲人成7777| 麻豆免费精品视频| 在线观看成人一级片| 久久深夜福利免费观看| 欧美freesex8一10精品| 18成人免费观看视频| 久久亚洲高清| 欧美激情亚洲另类| 一区二区日韩免费看| 欧美三级电影网| 中国日韩欧美久久久久久久久| 亚洲欧美日韩一区二区三区在线观看 | 一本久久a久久免费精品不卡| 在线一区二区三区四区五区| 欧美四级在线| 欧美专区中文字幕| 欧美激情一二区| 在线亚洲国产精品网站| 国产精品午夜国产小视频| 欧美一区二区三区四区夜夜大片| 久久阴道视频| 一本色道久久88综合亚洲精品ⅰ| 国产精品国产三级国产| 欧美中文字幕视频| 亚洲黑丝在线| 香蕉免费一区二区三区在线观看 | 亚洲欧洲午夜| 午夜精品在线视频| 一区二区三区无毛| 欧美日韩一区二区高清| 欧美一区午夜精品| 亚洲国产日韩欧美在线99| 亚洲综合国产精品| 在线观看日韩www视频免费| 欧美精品导航| 欧美资源在线观看| 亚洲久久成人| 久久综合给合久久狠狠狠97色69| 亚洲美女尤物影院| 国产美女精品视频| 欧美精品videossex性护士| 亚洲综合丁香| 亚洲人成精品久久久久| 久久久久久噜噜噜久久久精品| 99re66热这里只有精品4| 国产日韩精品入口| 欧美日韩精品一本二本三本| 久久男女视频| 欧美一区二区三区免费视频| 亚洲麻豆一区| 亚洲国产精品成人综合| 久久久久成人精品免费播放动漫| 在线一区二区三区四区五区| 亚洲国产一区视频| 国产视频精品xxxx| 国产精品久久久久久久一区探花 | 一区二区三区精品| 亚洲国产一区在线| 欧美a级片一区| 久久乐国产精品| 欧美尤物一区| 亚洲欧美视频一区| 久久久久免费观看| 午夜精品影院| 国产精品99久久99久久久二8| 亚洲人成网站999久久久综合| 老巨人导航500精品| 欧美一区二区三区免费看| 亚洲在线视频观看| 亚洲一区二区少妇| 亚洲在线视频免费观看| 中国成人在线视频| 亚洲网站啪啪| 亚洲自拍偷拍麻豆| 午夜一区二区三区在线观看 | 国产喷白浆一区二区三区| 国产精品乱码久久久久久| 国产精品v欧美精品∨日韩| 欧美三级小说| 国产精品美女www爽爽爽视频| 欧美性做爰毛片| 国产精品久久国产愉拍| 国产精品一区二区三区免费观看| 国产精品女主播| 国产日韩亚洲欧美综合| 国产一区高清视频| 亚洲高清久久| 亚洲乱亚洲高清| 亚洲在线国产日韩欧美| 欧美亚洲视频一区二区| 久久久久九九九九| 欧美高清在线一区二区| 亚洲品质自拍| 亚洲影视综合| 久久久久久久999精品视频| 老司机一区二区| 欧美日韩国产成人高清视频| 国产精品成人国产乱一区| 国产模特精品视频久久久久 | 国产亚洲欧美一区在线观看| 一区二区在线观看av| 91久久精品久久国产性色也91| 亚洲精品在线视频观看| 亚洲在线视频网站| 美女成人午夜| 一区二区三区波多野结衣在线观看| 亚洲欧美999| 欧美国产日韩一区二区三区| 国产精品视频一区二区三区| 在线观看欧美激情| 亚洲一区二区三区四区五区黄 | 亚洲午夜久久久| 久久视频这里只有精品| 亚洲精品乱码久久久久久久久| 亚洲欧美日本伦理| 欧美aⅴ一区二区三区视频| 国产精品久久久久久久浪潮网站 | 国产精品亚洲视频| 亚洲国产欧美日韩另类综合| 久久综合狠狠综合久久综青草 | 免费高清在线一区| 国产精品免费一区二区三区在线观看| 黄色日韩网站| 亚洲一区二区日本| 亚洲第一网站免费视频| 亚洲欧美日本另类| 欧美日韩一二三四五区| 影音先锋欧美精品| 久久av在线看|