USACO Section 2.1 Healthy Holsteins
/*
ID: lucien23
PROG: holstein
LANG: C++
*/ #include <iostream>
#include <fstream>
#include <vector>
using namespace std; bool compFun(int x, int y)
{
int temp, i = 0; while (true)
{
temp = 1 << i;
if (temp&x > temp&y)
{
return true;
} else if (temp&x < temp&y)
{
return false;
}
i++;
}
} int main()
{
ifstream infile("holstein.in");
ofstream outfile("holstein.out");
if(!infile || !outfile)
{
cout << "file operation failure!" << endl;
return -1;
} int arrCnt[15] = {1,3,7,15,31,63,127,255,511,1023,2047,4095,8191,16383,32767}; int V;
infile >> V;
int *minRequire = new int[V];
for (int i=0; i<V; i++)
{
infile >> minRequire[i];
}
int G;
infile >> G;
int **feeds = new int *[G];
for (int i=0; i<G; i++)
{
feeds[i] = new int[V];
for (int j=0; j<V; j++)
{
infile >> feeds[i][j];
}
} int minScoopsCnt = 16;
int minScoops = 0; int *sumVita = new int[V];
int sumScoops;
for (int i=1; i<=arrCnt[G-1]; i++)
{//穷举遍历每一种方案
for (int k=0; k<V; k++)
{
sumVita[k] = 0;
}
sumScoops = 0; for (int j=0; j<G; j++)
{//推断此方案中是否包括饲养类型j(利用移位运算)
int temp = 1 << j;
if ((temp & i) == temp)
{//包括类型j
for (int k=0; k<V; k++)
{
sumVita[k] += feeds[j][k];
}
sumScoops++;
}
} int k;
for (k=0; k<V; k++)
{
if (sumVita[k] < minRequire[k])
break;
}
if (k==V && (sumScoops<minScoopsCnt || (sumScoops==minScoops && compFun(minScoops, i))))
{
minScoopsCnt = sumScoops;
minScoops = i;
}
} outfile << minScoopsCnt;
for (int j=0; j<G; j++)
{
int temp = 1 << j;
if ((temp & minScoops) == temp)
{
outfile << " " << j+1;
}
}
outfile << endl; return 0;
}
USACO Section 2.1 Healthy Holsteins的更多相关文章
- 【USACO 2.1】Healthy Holsteins
/* TASK: holstein LANG: C++ URL: http://train.usaco.org/usacoprob2?a=SgkbOSkonr2&S=holstein SOLV ...
- USACO Healthy Holsteins
首先看题目: Healthy HolsteinsBurch & Kolstad Farmer John prides himself on having the healthiest dair ...
- USACO 2.1 Healthy Holsteins
Healthy HolsteinsBurch & Kolstad Farmer John prides himself on having the healthiest dairy cows ...
- 洛谷 P1460 健康的荷斯坦奶牛 Healthy Holsteins
P1460 健康的荷斯坦奶牛 Healthy Holsteins 题目描述 农民JOHN以拥有世界上最健康的奶牛为傲.他知道每种饲料中所包含的牛所需的最低的维他命量是多少.请你帮助农夫喂养他的牛,以保 ...
- P1460 健康的荷斯坦奶牛 Healthy Holsteins
P1460 健康的荷斯坦奶牛 Healthy Holsteins 题目描述 农民JOHN以拥有世界上最健康的奶牛为傲.他知道每种饲料中所包含的牛所需的最低的维他命量是多少.请你帮助农夫喂养他的牛,以保 ...
- USACO Section2.1 Healthy Holsteins 解题报告 【icedream61】
holstein解题报告 --------------------------------------------------------------------------------------- ...
- USACO Healthy Holsteins DFS
使用排列组合,遍历所有可能的情况C(1)+C(2)+C(3)……C(n)= 2^G种组合 数据规模不大,暴力过去最多也就是2^15 = 23768种情况 所以就暴力咯,不过还是Debug了一会 Sou ...
- USACO Section 1.3 题解 (洛谷OJ P1209 P1444 P3650 P2693)
usaco ch1.4 sort(d , d + c, [](int a, int b) -> bool { return a > b; }); 生成与过滤 generator&& ...
- 洛谷P1460 健康的荷斯坦奶牛 Healthy Holsteins
题目描述 农民JOHN以拥有世界上最健康的奶牛为傲.他知道每种饲料中所包含的牛所需的最低的维他命量是多少.请你帮助农夫喂养他的牛,以保持它们的健康,使喂给牛的饲料的种数最少. 给出牛所需的最低的维他命 ...
随机推荐
- DataProtection Key的选择
代码位于: Microsoft.AspNetCore.DataProtection.KeyManagement.DefaultKeyResolver.cs private IKey FindDefau ...
- 【译】Asp.Net Identity Cookies 格式化
原文出处 Trailmax Tech Max Vasilyev: ASP.Net MVC development in Aberdeen, Scotland 中英对照版 我的读者联系到我,并向我提出了 ...
- Velocity(6)——velocity遍历josn格式的字符串
使用velocity脚本语言遍历josn格式的字符串 1.由于数据库会存储一些json格式的字符,为方便以后使用筛选 如果这些数据我们查出来直接遍历使用velocity是根本行不通的,例如这样的话:j ...
- HQL连接查询和注解
HQL连接查询和注解 一:HQL连接查询 各种连接查询: 内连接:inner join或join From Entity inner [inner] join [fetch] Entity.prope ...
- 五、VueJs 填坑日记之将接口用webpack代理到本地
上一篇博文,我们已经顺利的从cnodejs.org请求到了数据,但是大家可以注意到我们的/src/api/index.js的第一句就是: // 配置API接口地址 var root = 'https: ...
- 前端设计师如何提高UI界面中的阅读性
阅读体验是ui设计中必不可少的一项,良好的设计应该都是可读的设计,如果信息都无法正常而清晰的传达,那么设计就失去了意义.设计的可读性和排版设计息息相关,这也就跟设计师的设计功底息息相关.下面简单介绍文 ...
- iOS获取所有机型
1.手机系统版本:9.1 NSString* phoneVersion = [[UIDevice currentDevice] systemVersion]; 2.手机类型:iPhone 6 NSSt ...
- java对象拷贝和复制
参考文章:http://blog.csdn.net/XIAXIA__/article/details/41652057 解决问题:深拷贝.浅拷贝 和普通的对象赋值有什么区别? 对象复制 例如:Pers ...
- SQL Server 基本操作之三种增加法
前言: 数据库操作避免不了对数据的操作,操作方法大同小异,万变不离其宗,今就写一下各种花式操作的根本增删改查四种操作,今天我们就来说一下增加操作的三种方法 正文: 增加操作是对数据库进行数据行的添加, ...
- Mac安装Elasticsearch时提示:No Java runtime present, requesting install.
没有安装java的童鞋可以先去安装一下,地址:https://www.java.com/zh_CN/ 安装之后还是提示如下错误: ➜ elasticsearch-2.4.3 bin/elasticse ...