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

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

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

導(dǎo)航

統(tǒng)計(jì)

常用鏈接

留言簿(1)

隨筆檔案(2)

文章分類(23)

文章檔案(22)

搜索

最新評(píng)論

閱讀排行榜

評(píng)論排行榜

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
            亚洲欧美制服中文字幕| 韩国成人精品a∨在线观看| 一本一本a久久| 亚洲精品永久免费| 国产精品你懂的| 亚洲美女性视频| 亚洲欧洲一区| 麻豆国产va免费精品高清在线| 久久久一区二区| 欧美v日韩v国产v| 最新成人在线| 亚洲视频一区在线| 欧美在线亚洲在线| 美女主播视频一区| 欧美精品久久久久久久| 国产精品成人va在线观看| 国产精品视频xxx| 国产日韩亚洲欧美精品| 在线日本欧美| 日韩午夜高潮| 欧美一区二区在线视频| 女女同性精品视频| 在线亚洲自拍| 久久深夜福利| 欧美亚男人的天堂| 激情亚洲网站| 亚洲午夜日本在线观看| 性色av一区二区三区红粉影视| 久久久精品国产99久久精品芒果| 欧美激情2020午夜免费观看| 亚洲视频在线看| 久久伊伊香蕉| 国产精品九九| 日韩视频一区二区在线观看| 欧美一级片久久久久久久| 欧美激情欧美激情在线五月| 亚洲视频在线看| 欧美成人黑人xx视频免费观看| 国产欧美精品| 亚洲午夜在线| 亚洲国产精品精华液网站| 午夜精品一区二区三区在线视| 欧美精品一区在线播放| 伊人久久大香线蕉综合热线 | 欧美激情亚洲自拍| 国产亚洲免费的视频看| 亚洲午夜一区二区三区| 亚洲国产合集| 久久在线播放| 依依成人综合视频| 久久激情综合网| 亚洲特黄一级片| 欧美午夜精品久久久久久超碰| 亚洲精品久久久久中文字幕欢迎你 | 欧美日韩视频第一区| 国内精品伊人久久久久av影院| 欧美精品黄色| 欧美国产日韩二区| 一区在线播放视频| 久久精品99国产精品酒店日本| aa国产精品| 欧美日韩亚洲一区二区三区| 99精品视频网| 日韩一区二区精品| 欧美激情一区二区在线 | 妖精视频成人观看www| 欧美成人一区二区三区| 久久婷婷国产综合国色天香| 在线观看一区| 亚洲第一视频| 欧美精品一区二区三区在线播放| 亚洲精品久久久久| 亚洲人www| 欧美性开放视频| 欧美一二三视频| 久久成人一区二区| 在线观看日韩专区| 欧美电影免费观看高清完整版| 美国十次了思思久久精品导航| 亚洲国产精品久久久久婷婷老年| 欧美韩日精品| 欧美日韩福利在线观看| 亚洲一二三区视频在线观看| 亚洲欧美国产视频| 国内久久精品| 亚洲精品小视频| 国产精品自在线| 免费欧美日韩| 欧美午夜精品久久久久久人妖| 欧美资源在线观看| 久久综合九色综合网站| 99国产成+人+综合+亚洲欧美| 在线视频欧美精品| 狠狠综合久久| 一区二区高清在线| 黄色精品一二区| 日韩视频精品在线| 国模吧视频一区| 亚洲精品乱码久久久久| 国产欧美日韩伦理| 亚洲国产你懂的| 国产婷婷色综合av蜜臀av | 亚洲高清一二三区| 国产精品福利在线观看网址| 久久久噜久噜久久综合| 欧美精品一区二区视频| 久久成人免费网| 欧美日韩免费看| 久久综合色影院| 欧美亚洲不卡| 亚洲国产专区| 国产一区二区三区久久 | 欧美精品 日韩| 久久久久久国产精品一区| 欧美日韩另类丝袜其他| 噜噜噜91成人网| 国产精品视频你懂的| 欧美大胆a视频| 国产在线观看91精品一区| 夜夜嗨一区二区三区| 最新国产乱人伦偷精品免费网站| 西西人体一区二区| 亚洲一区bb| 欧美区日韩区| 亚洲国产婷婷香蕉久久久久久99| 激情av一区二区| 性欧美大战久久久久久久久| 亚洲一区视频在线| 欧美日本国产视频| 亚洲国产一区二区a毛片| 精品成人一区二区| 欧美伊人久久大香线蕉综合69| 亚洲欧美日韩国产另类专区| 欧美精品福利在线| 亚洲成人在线视频网站| 亚洲第一福利社区| 久久狠狠亚洲综合| 久久久久久久久久看片| 国产午夜精品理论片a级大结局 | 亚欧成人在线| 久久精品综合| 国内久久婷婷综合| 久久久青草婷婷精品综合日韩| 久久亚洲不卡| 亚洲第一页自拍| 能在线观看的日韩av| 欧美激情亚洲精品| 亚洲另类在线视频| 欧美日韩视频在线一区二区观看视频 | 美腿丝袜亚洲色图| 欧美二区在线| 999亚洲国产精| 欧美体内谢she精2性欧美| 日韩视频免费观看| 亚洲欧美国产三级| 国产精品尤物| 久久高清国产| 亚洲福利在线看| 亚洲图片在区色| 国产欧美精品国产国产专区| 久久国内精品自在自线400部| 欧美二区在线| 亚洲欧美日韩国产成人精品影院| 国产午夜精品久久久久久免费视| 久久婷婷人人澡人人喊人人爽| 亚洲国产一区二区三区在线播| 亚洲色图在线视频| 国产日韩欧美亚洲| 免费影视亚洲| 亚洲天堂男人| 欧美成人免费网| 亚洲精品一区二区三区不| 久久视频精品在线| 韩日欧美一区| 欧美激情在线播放| 亚洲欧美综合一区| 亚洲成人资源网| 欧美一区二区三区四区在线观看| 一区久久精品| 国产精品成人一区二区三区夜夜夜| 欧美在线免费视频| 亚洲精品视频在线| 久热国产精品| 亚洲综合色自拍一区| 亚洲电影免费观看高清完整版在线观看 | 欧美一区日韩一区| 亚洲人成小说网站色在线| 国产精品国产三级国产aⅴ浪潮 | 欧美日韩色综合| 久久精品国产久精国产一老狼| 日韩视频一区二区三区| 老司机午夜精品视频在线观看| 亚洲视频精品在线| 亚洲韩国青草视频| 国产一区高清视频| 国产精品久久网站| 欧美精品一区二区三区蜜臀| 久久久久久免费| 午夜精品福利电影| 亚洲婷婷在线|