usaco 2.1.4 Healthy Holsteins

原创 2012年03月30日 21:34:36

surprise!

在nnnnnnn久没码代码然后前两天码了一个还出现了本机和上传结果不符的诡异情况后,今天终于rp爆发了.一次编译过+一次提交过,虽然查逻辑错还是花了挺久,大概有三处,不过还是很满意的,而且第一次用位运算,虽然犯了个2,纠结了好久,但总体还是不错的,虽然害的没睡成午觉...

Healthy Holsteins
Burch & Kolstad

Farmer John prides himself on having the healthiest dairy cows in the world. He knows the vitamin content for one scoop of each feed type and the minimum daily vitamin requirement for the cows. Help Farmer John feed his cows so they stay healthy while minimizing the number of scoops that a cow is fed.

Given the daily requirements of each kind of vitamin that a cow needs, identify the smallest combination of scoops of feed a cow can be fed in order to meet at least the minimum vitamin requirements.

Vitamins are measured in integer units. Cows can be fed at most one scoop of any feed type. It is guaranteed that a solution exists for all contest input data.

PROGRAM NAME: holstein

INPUT FORMAT

Line 1: integer V (1 <= V <= 25), the number of types of vitamins
Line 2: V integers (1 <= each one <= 1000), the minimum requirement for each of the V vitamins that a cow requires each day
Line 3: integer G (1 <= G <= 15), the number of types of feeds available
Lines 4..G+3: V integers (0 <= each one <= 1000), the amount of each vitamin that one scoop of this feed contains. The first line of these G lines describes feed #1; the second line describes feed #2; and so on.

SAMPLE INPUT (file holstein.in)

4
100 200 300 400
3
50   50  50  50
200 300 200 300
900 150 389 399

OUTPUT FORMAT

The output is a single line of output that contains:

  • the minimum number of scoops a cow must eat, followed by:
  • a SORTED list (from smallest to largest) of the feed types the cow is given
If more than one set of feedtypes yield a minimum of scoops, choose the set with the smallest feedtype numbers.

SAMPLE OUTPUT (file holstein.out)

2 1 3

喵~

/*
ID: wtff0411
PROG: holstein
LANG: C++
*/
#include <iostream>
#include <fstream>
#include <string>
#include <cstring>
#include <vector>
#include <cmath>
#include <queue>
#include <algorithm>

using namespace std;

int main()
{
    freopen("holstein.in","r",stdin);
    freopen("holstein.out","w",stdout);
    int v,g;
    int i,j,k;
    int r[100];
    int s[50][50];
    
    cin>>v;
    
    for(i=0;i<v;i++)
    cin>>r[i];
    cin>>g;
    for(i=0;i<g;i++)
        for(j=0;j<v;j++)
           cin>>s[i][j];
    int m=pow(2.0,(double)g);
    int resn=100,ress=1000000;
    for(i=1;i<m;i++)
    {
        int tempr[100];
        memset(tempr,0,sizeof(tempr));
        int tempn=0;
        int temp=i;
        for(j=0;j<g;j++)
        {
            if(temp&1)
            {
            for(k=0;k<v;k++)
            {
                tempr[k]+=s[j][k];
                
            }
            tempn++;
            }
            if(tempn>resn)break;
            temp=temp>>1;//aha shit
        }
        
        bool flag=false;
        for(k=0;k<v;k++)
            {
                if(tempr[k]<r[k])
               { flag=true;
               break;
               }
            }
         //  cout<<tempn<<endl; 
        if(flag==false&&((tempn<resn)||((tempn==resn)&&(i<ress))))
        {
            
            resn=tempn;
            ress=i;
        }
        
    }
    cout<<resn;
    for(j=1;j<=g;j++)
        {
        if(ress&1)
            {
                  cout<<" "<<j;
            }
            ress=ress>>1;
        }
        cout<<endl;//well...- -that's it
    //system("pause");
    return 0;
}
码代码..只要自己逻辑比较清晰,最后能出正确的结果,果然还是一件很爽的事...

相关文章推荐

Usaco 2.1.4 健康的荷斯坦奶牛(Healthy Holsteins)

题目:  健康的荷斯坦奶牛 来源:  Usaco2.1.4 题目大意:  给定V个值,G个方案,求通过最小的方案数使这V个值全为不大于...

Healthy Holsteins_usaco2.1.4_codevs2044_dfs

题目描述 Description农民JOHN以拥有世界上最健康的奶牛为傲。他知道每种饲料中所包含的牛所需的最低的维他命量是多少。请你帮助农夫喂养他的牛,以保持它们的健康,使喂给牛的饲料的种数最少。给出...
  • jpwang8
  • jpwang8
  • 2016年08月09日 16:22
  • 154

[USACO 2.1.4] Healthy Holsteins

[题目描述] Healthy Holsteins 健康的好斯坦奶牛 农民JOHN以拥有世界上最健康的奶牛为骄傲。他知道每种饲料中所包含的的牛所需的最低的维他命量是多少。请你帮助农夫喂养他的牛...

USACO 2.1.4Healthy Holsteins

// holstein.cpp : 定义控制台应用程序的入口点。 // /* ID: maiyuet1 PROG: holstein LANG: C++ */ //#include "stdafx.h...

USACO:2.1.4 Healthy Holsteins 健康的好斯坦奶牛

2.1.4 Healthy Holsteins 健康的好斯坦奶牛 一、题目描述 农民JOHN以拥有世界上最健康的奶牛为傲。他知道每种饲料中所包含的牛所需的最低的维他命量是多少。请你帮助农夫喂养他的...
  • E_pen
  • E_pen
  • 2015年01月23日 22:07
  • 1275

USACO 2.1.4 Healthy Holsteins

一 .题目描述 Farmer John prides himself on having the healthiest dairy cows in the world. He knows the v...
  • lhyer
  • lhyer
  • 2015年08月03日 19:30
  • 356

usaco2.1.4 Healthy Holsteins

一 原题 Healthy Holsteins Burch & Kolstad Farmer John prides himself on having the healthiest dair...

USACO Section 2.1 Healthy Holsteins

/* ID: lucien23 PROG: holstein LANG: C++ */ #include #include #include using namespace std; boo...

[USACO]Healthy Holsteins

Healthy Holsteins Burch & Kolstad Farmer John prides himself on having the healthiest dairy cows i...

USACO Healthy Holsteins

深搜,注意剪枝 /* ID: wangxin12 PROG: holstein LANG: C++ */ #include #include #include #include ...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:usaco 2.1.4 Healthy Holsteins
举报原因:
原因补充:

(最多只允许输入30个字)