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以拥有世界上最健康的奶牛为傲.他知道每种饲料中所包含的牛所需的最低的维他命量是多少.请你帮助农夫喂养他的牛,以保持它们的健康,使喂给牛的饲料的种数最少. 给出牛所需的最低的维他命 ...
随机推荐
- javaMybatis映射属性,高级映射
映射文件的sql属性: id:标识符(一般都是dao层方法名) resultType:sql返回类型 resultMap:放回的映射类型 parameterType:参数类型 useGenerated ...
- 【分享】jQuery无插件实现 鼠标拖动图片切换 功能
前言 我就想随便叨逼叨几句,爱看就看几句,不爱看就直接跳过看正文就好啦~ 这个方法是仿写页面时我自己研究出来,可能有比我更简单的方法. 但我不管,因为我没查我不知道,我就觉得我的最好啦,耶耶耶~ 效果 ...
- [转载] ETL和Kettle
http://tech.ccidnet.com/art/1105/20080407/1411567_1.html http://blog.csdn.net/cissyring/article/deta ...
- 【转】MYSQL 使用SQLyog导入遇到问题解决
原文地址:http://blog.163.com/o5655@126/blog/static/1667428342010910112510738/ 昨天公司想要将一个数据库的数据导出再导入到另外一个 ...
- Caused by: org.xml.sax.SAXParseException; lineNumber: 4; columnNumber: 49; 前言中不允许有内容。
今天刚开始学习mybatis时,自己去尝试使用mybatis链接数据库,操作数据局时,报了一个下面的错误 Caused by: org.xml.sax.SAXParseException; lineN ...
- mysql实现高可用架构之MHA
一.简介 MHA(Master HA)是一款开源的 MySQL 的高可用程序,它为 MySQL 主从复制架构提供了 automating master failover 功能.MHA 在监控到 mas ...
- 泛型里的super和extend
<? extends T>和<? super T>应该怎么用? 网上看到一些比较难懂的回答,但是在EffectiveJava(2th Edition)遇到简单明了的解释: If ...
- 【正则表达式】--python(表示字符)
[前修知识] match :匹配 span:范围 match 是从头往后开始匹配,search不按照顺序,直接获取自己想要的,有就显示,没有就None r 代表反转义,前面也提到过这个知识,如果 ...
- gdb的多线程调试
info threads 可以查看当前进程有哪些线程 thread ID 可以切换到线程ID bt 查看当前线程堆栈 set scheduler-locking on多线程调试过程中, 线程会来回切换 ...
- Rsync同步、Rsync+Lsync实时同步
Rsync同步.Rsync+Lsync实时同步 原创博文http://www.cnblogs.com/elvi/p/7658049.html #!/bin/sh #Myde by Elven @ #c ...