UVa 11308 - Bankrupt Baker
题目大意:给出一些原料和价钱和若干份菜谱,每份菜谱都标明所需的原料和数量,找出所有不超过预算的菜谱。
没什么好说的,主要是对map的运用。
#include <cstdio>
#include <string>
#include <map>
#include <iostream>
#include <cctype>
#include <algorithm>
using namespace std;
typedef map<string, int> msi; struct Recipe
{
string name;
int cost;
bool operator < (const Recipe& r) const
{
if (cost != r.cost) return cost < r.cost;
return name < r.name;
}
}recipe[]; int main()
{
#ifdef LOCAL
freopen("in", "r", stdin);
#endif
int T;
cin >> T;
getchar();
msi ingredient;
while (T--)
{
string title;
getline(cin, title);
transform(title.begin(), title.end(), title.begin(), ::toupper);
int m, n, b;
cin >> m >> n >> b;
getchar();
ingredient.clear();
string str;
int x;
for (int i = ; i < m; i++)
{
cin >> str >> x;
getchar();
ingredient[str] = x;
}
for (int i = ; i < n; i++)
{
getline(cin, recipe[i].name);
recipe[i].cost = ;
int k;
cin >> k;
getchar();
for (int j = ; j < k; j++)
{
cin >> str >> x;
getchar();
recipe[i].cost += ingredient[str]*x;
}
}
sort(recipe, recipe+n);
cout << title << endl;
if (recipe[].cost > b)
{
cout << "Too expensive!" << endl << endl;
continue;
}
for (int i = ; i < n; i++)
{
if (recipe[i].cost > b) break;
cout << recipe[i].name << endl;
}
cout << endl;
}
return ;
}
UVa 11308 - Bankrupt Baker的更多相关文章
- uva 1354 Mobile Computing ——yhx
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGcAAANuCAYAAAC7f2QuAAAgAElEQVR4nOy9XUhjWbo3vu72RRgkF5
- UVA 10564 Paths through the Hourglass[DP 打印]
UVA - 10564 Paths through the Hourglass 题意: 要求从第一层走到最下面一层,只能往左下或右下走 问有多少条路径之和刚好等于S? 如果有的话,输出字典序最小的路径 ...
- UVA 11404 Palindromic Subsequence[DP LCS 打印]
UVA - 11404 Palindromic Subsequence 题意:一个字符串,删去0个或多个字符,输出字典序最小且最长的回文字符串 不要求路径区间DP都可以做 然而要字典序最小 倒过来求L ...
- UVA&&POJ离散概率与数学期望入门练习[4]
POJ3869 Headshot 题意:给出左轮手枪的子弹序列,打了一枪没子弹,要使下一枪也没子弹概率最大应该rotate还是shoot 条件概率,|00|/(|00|+|01|)和|0|/n谁大的问 ...
- UVA计数方法练习[3]
UVA - 11538 Chess Queen 题意:n*m放置两个互相攻击的后的方案数 分开讨论行 列 两条对角线 一个求和式 可以化简后计算 // // main.cpp // uva11538 ...
- UVA数学入门训练Round1[6]
UVA - 11388 GCD LCM 题意:输入g和l,找到a和b,gcd(a,b)=g,lacm(a,b)=l,a<b且a最小 g不能整除l时无解,否则一定g,l最小 #include &l ...
- UVA - 1625 Color Length[序列DP 代价计算技巧]
UVA - 1625 Color Length 白书 很明显f[i][j]表示第一个取到i第二个取到j的代价 问题在于代价的计算,并不知道每种颜色的开始和结束 和模拟赛那道环形DP很想,计算这 ...
- UVA - 10375 Choose and divide[唯一分解定理]
UVA - 10375 Choose and divide Choose and divide Time Limit: 1000MS Memory Limit: 65536K Total Subm ...
- UVA - 11584 Partitioning by Palindromes[序列DP]
UVA - 11584 Partitioning by Palindromes We say a sequence of char- acters is a palindrome if it is t ...
随机推荐
- 保存iptables的防火墙规则的方法【转载】
转自: 保存iptables的防火墙规则的方法 - 51CTO.COMhttp://os.51cto.com/art/201103/249504.htm 保存iptables的防火墙规则的方法如下: ...
- vm选项大全
http://hllvm.group.iteye.com/group/topic/27945 java -XX:后边的总记不住 vm选项大全 http://www.oracle.com/technet ...
- Myeclipse8.5中svn插件安装方法总结
[转]http://lwcheng1985.iteye.com/blog/696143 有改动 方法一:在线安装 1.打开HELP->MyEclipse Configuration Cent ...
- Scroll View 深入
转载自:http://mobile.51cto.com/hot-430409.htm 可能你很难相信,UIScrollView和一个标准的UIView差异并不大,scroll view确实会多一些方法 ...
- 总结自己的Git常用命令
总结自己的Git常用命令 使用git也有一段时间了,把自己常用的命令用自己的描述记录起来,方便自己备忘也方便其他人参考. 目录: 最基本的命令: git clone 拷贝并跟踪远程的master分支. ...
- linux shell——md5sum,sha1sum,sort,uniq (转)
1.文件校验 1. md5sum eg: md5sum filename 注:生成一个128位的二进制位,即32位的十六进制字符串 1.验证文件的正确性: md5sum file1 file2 &g ...
- [转]Firefox拦截12306订票网站的解决办法
解决方法:1.找到firefox选项设置(Ubuntu下的ff的选项在[Edit]-[Preferences]中) 2.点击[Advanced]-[Encryption]-[View Certific ...
- Tower Defense Game
Tower Defense Game 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 There is a tower defense game with n level ...
- 什么是deferred对象
$.when().done().then()的用法 http://www.cnblogs.com/tiancai/p/5817996.html jQuery的开发速度很快,几乎每半年一个大版本,每两 ...
- (译)Windsor入门教程---第三部分 编写第一个Installer
原文:http://docs.castleproject.org/Windsor.Windsor-tutorial-ASP-NET-MVC-3-application-To-be-Seen.ashx ...