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

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 幻浪天空領主 閱讀(416) 評論(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>
            亚洲午夜在线观看视频在线| 久久久噜噜噜久久人人看| 亚洲日本在线视频观看| a4yy欧美一区二区三区| 亚洲一二区在线| 亚洲网在线观看| 久久久噜噜噜久噜久久| 亚洲国产成人不卡| 亚洲永久精品大片| 免费成人av| 亚洲精品免费在线播放| 欧美日韩三级一区二区| 精品动漫一区二区| 亚洲视频在线观看一区| 欧美顶级少妇做爰| 亚洲网址在线| 国外精品视频| 亚洲免费视频中文字幕| 欧美二区在线播放| 欧美日韩国产精品| 亚洲日韩视频| 久久―日本道色综合久久| 一本久久综合亚洲鲁鲁| 久久久久久亚洲综合影院红桃| 亚洲国产精品999| 夜夜嗨av一区二区三区网站四季av| 久久免费视频一区| 国产自产在线视频一区| 午夜亚洲激情| 亚洲一区图片| 国产精品超碰97尤物18| 亚洲免费观看高清完整版在线观看熊 | 欧美电影在线观看| 国产精品白丝jk黑袜喷水| 两个人的视频www国产精品| 欧美一区二区视频免费观看| 欧美日韩综合网| 日韩视频在线观看| 最新精品在线| 欧美国产视频日韩| 亚洲精品美女久久久久| 午夜精品理论片| 国产视频一区在线观看| 欧美一区二区在线观看| 亚洲一区二区视频在线| 亚洲伦理精品| 久久伊人精品天天| 久久国产精品久久精品国产 | 久久夜色精品一区| 久久久久国产精品午夜一区| 亚洲男人的天堂在线观看| 欧美激情成人在线视频| 欧美gay视频激情| 美女露胸一区二区三区| 亚洲国产精品va在线看黑人 | 日韩视频精品| 国产精品一区免费观看| 欧美与黑人午夜性猛交久久久| 欧美精品videossex性护士| 99精品热6080yy久久| 麻豆精品视频| 欧美刺激午夜性久久久久久久| 国产一区视频在线观看免费| 午夜精品福利一区二区三区av| 亚洲制服丝袜在线| 欧美午夜剧场| 亚洲天天影视| 欧美一区免费| 国产一区二区三区黄| 亚洲成人自拍视频| 欧美日韩亚洲免费| 99视频精品全国免费| 亚洲天天影视| 国产精品进线69影院| 六月婷婷一区| 亚洲风情在线资源站| 免费久久99精品国产自| 午夜精品久久久久久久99黑人| 欧美视频一区二区| 亚洲一区二区三区免费视频| 欧美中文字幕在线| 亚洲电影观看| 欧美一级久久| 另类激情亚洲| 亚洲免费观看在线观看| 欧美色大人视频| 午夜欧美精品久久久久久久| 在线一区二区视频| 免费日韩视频| 一级成人国产| 久久久www| 国产精品视频999| 亚洲美女色禁图| 午夜精品福利在线| 亚洲第一福利在线观看| 欧美激情精品久久久久久| 一区二区三区四区五区精品| 久久精品国产精品亚洲精品| 欧美性猛交xxxx乱大交蜜桃| 午夜在线视频一区二区区别| 欧美高清在线观看| 亚洲欧美日韩人成在线播放| 在线观看一区二区视频| 欧美日韩另类字幕中文| 久久精彩免费视频| 久久久久久久性| 亚洲另类在线一区| 国产一区二区三区在线观看网站| 免费成人黄色| 性做久久久久久久久| 亚洲国产天堂久久国产91| 精品成人在线观看| 欧美性jizz18性欧美| 开心色5月久久精品| 欧美 日韩 国产精品免费观看| 在线视频你懂得一区| 狠狠色丁香婷婷综合| 国产精品高潮呻吟视频| 男人插女人欧美| 久久se精品一区二区| 久久免费少妇高潮久久精品99| 一区二区冒白浆视频| 1024亚洲| 国产在线视频不卡二| 欧美午夜不卡在线观看免费 | 亚洲无限av看| 最新亚洲视频| 欧美大片专区| 卡一卡二国产精品| 久久精品一区二区国产| 亚洲在线国产日韩欧美| aa日韩免费精品视频一| 亚洲福利电影| 亚洲国产高清aⅴ视频| 国产综合av| 国产亚洲福利| 国产偷久久久精品专区| 国产精品自拍三区| 国产精品一区二区久久久 | 亚洲欧美日韩久久精品| 亚洲精品乱码| 99国产精品99久久久久久| 最新中文字幕亚洲| 亚洲伦理中文字幕| 欧美伊人久久大香线蕉综合69| 亚洲综合色丁香婷婷六月图片| 一区二区av在线| 亚洲午夜羞羞片| 亚洲欧美乱综合| 欧美中文字幕| 久久久久久一区二区三区| 久久综合狠狠综合久久综合88| 久久精品日产第一区二区| 久久九九久精品国产免费直播| 久久成人免费电影| 久久男人资源视频| 欧美国产欧美综合 | 久久国产福利国产秒拍| 欧美中文日韩| 久久只精品国产| 免费视频久久| 亚洲精品国产精品国产自| 99re6这里只有精品| 亚洲婷婷综合久久一本伊一区| 亚洲欧美国产77777| 亚洲狠狠婷婷| 在线一区二区三区四区五区| 欧美国产日韩二区| 亚洲人成毛片在线播放| 亚洲天堂成人在线观看| 久久精品国产96久久久香蕉| 蜜臀久久久99精品久久久久久 | 欧美精品videossex性护士| 国产精品hd| 激情成人综合网| 99re热这里只有精品视频| 性欧美精品高清| 一区二区不卡在线视频 午夜欧美不卡在 | 亚洲精品乱码久久久久久黑人 | 亚洲精品色婷婷福利天堂| 亚洲视频专区在线| 久久精品国产一区二区三区免费看 | 亚洲欧洲日韩综合二区| 影音先锋久久| 国产婷婷成人久久av免费高清| 一区二区三区中文在线观看| 一级日韩一区在线观看| 久久精品人人做人人综合| 亚洲日本视频| 午夜精品亚洲| 欧美日本一区二区高清播放视频| 女同性一区二区三区人了人一| 国产精品久久久久久久久久久久| 黄色成人91| 亚洲欧美日本国产有色| 欧美国产在线视频| 欧美一区午夜视频在线观看| 欧美日韩亚洲国产精品| 亚洲三级影片| 久热这里只精品99re8久|