USACO chapter 3 section 3 Feed Ratios

USER: tian tianbing [tbbd4261]
TASK: ratios
LANG: C++
Compiling...
Compile: OK
Executing...
Test 1: TEST OK [0.043 secs, 3016 KB]
Test 2: TEST OK [0.032 secs, 3016 KB]
Test 3: TEST OK [0.032 secs, 3016 KB]
Test 4: TEST OK [0.022 secs, 3016 KB]
Test 5: TEST OK [0.022 secs, 3016 KB]
Test 6: TEST OK [0.032 secs, 3016 KB]
All tests OK.

Your program ('ratios') produced all correct answers! This is your submission #18 for this problem. Congratulations!

Here are the test data inputs:

------- test 1 -------
5 8 0
3 5 4
1 3 0
6 2 0
------- test 2 -------
3 4 5
1 2 3
3 7 1
2 1 2
------- test 3 -------
20 22 24
4 5 5
9 5 6
12 12 14
------- test 4 -------
80 85 80
98 97 96
89 87 88
78 79 80
------- test 5 -------
99 99 99
1 0 0
0 1 0
0 0 1
------- test 6 -------
93 95 97
98 0 0
0 98 0
0 0 98
Keep up the good work!

Thanks for your submission!
直接枚举就能过了,提交了18次,不知道为什么用fin读不了,后来还是让同学帮我改成C的文件读入才过的
到现在还是不知道为什么。
要注意比例和饲料都是非负的小于100的,也就是说可能出现0的情况,要小心。
/*
ID:tbbd4261
PROG:ratios
LANG:C++
*/

#include
<fstream>
#include 
<stdio.h>
using namespace std;
//fstream fin("ratios.in");
ofstream fout("ratios.out");

int main()
{
    
int food[4][4];
    freopen(
"ratios.in","r",stdin);
    freopen(
"ratios.out","w",stdout);
    
int i,j,k,minsum=0xffffff,a=0,b=0,c=0,d=0;
    
for(i=0; i<4; i++)
        
for(j=1; j<=3; j++)
             scanf(
"%d",&food[i][j]);
    
int n1,n2,n3;
    
bool f1,f2,f=false;
    
for(i=0; i<=100; i++)
        
for(j=0; j<=100; j++)
             
for(k=0; k<=100; k++){
                     n1
=food[1][1]*i+food[2][1]*j+food[3][1]*k;
                     n2
=food[1][2]*i+food[2][2]*j+food[3][2]*k;
                     n3
=food[1][3]*i+food[2][3]*j+food[3][3]*k;
            
                 
int t=0;  f1=false; f2=false;
                 
if(food[0][1]==0){
                     f1
=true;
                     
if(n1!=0)continue;
                 }
else{
                      
if(n1%food[0][1]!=0)continue;
                      t
=n1/food[0][1];
                 }
                 
                 
if(food[0][2]==0){
                      f2
=true;
                      
if(n2!=0)continue;
                 }
else {
                       
if(n2%food[0][2]!=0)continue;
                       
if(f1==true)t=n2/food[0][2];
                       
else if(n2/food[0][2]!=t)continue;
                 }
                 
                 
if(food[0][3]==0){
                       
if(n3!=0)continue;  
                 }
else{
                       
if(n3%food[0][3]!=0)continue;
                       
if(f1&&f2)t=n3/food[0][3];
                       
if((f1==false ||f2==false)&&n3/food[0][3]!=t)continue;
                 }
             
                 
if( n1+n2+n3<minsum&&(n1||n2||n3)){
                     f
=true;
                  minsum
=n1+n2+n3;  
                  a
=i; b=j; c=k; d=t; 
                  }
    }
    
if(f) fout<<a<<' '<<b<<' '<<c<<' '<<d<<endl;
    
else fout<<"NONE"<<endl;   
    
return 0;
}

posted on 2010-08-06 20:08 田兵 阅读(150) 评论(0)  编辑 收藏 引用 所属分类: USACO


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   博问   Chat2DB   管理


<2010年8月>
25262728293031
1234567
891011121314
15161718192021
22232425262728
2930311234

导航

统计

常用链接

留言簿(2)

随笔分类(65)

随笔档案(65)

文章档案(2)

ACM

搜索

积分与排名

最新随笔

最新评论

阅读排行榜