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 ...
随机推荐
- MVC 使用Jquery的$.post传递参数
MVC中,如果要使用 $.post 给 COntroller 传递参数,需要类实现 属性 get set,这样才行
- index.do为后缀的是什么开发语言? 有什么技术特点?
@Override 重写父类的方法.@Nullable 表示定义的字段可以为空. 一般情况下扩展名可以体现出一个网站使用的技术,***.html?id=***,这个就是普通的html页面,然后通过ja ...
- C#实现http断点下载
我们寄希望于万能的解决方案,但是现实的情况总是很糟糕.在软件编程的世界中,技术分散的情况尤为严重,且不说各种语言拥有的优势不能融合,单就一门语言而言,就拥有众多的技术和相关技术需要学习.网络编程就是这 ...
- Android消息提示框Toast
Android消息提示框Toast Toast是Android中一种简易的消息提示框.和Dialog不一样的是,Toast是没有焦点的,toast提示框不能被用户点击,而且Toast显示的时间有限,t ...
- jq之简单的表单验证
<body> <form method="post" action=""> <div class="int"& ...
- BD string 百度之星初赛的题目 数学
http://acm.hdu.edu.cn/showproblem.php?pid=5694 可以说这道题目挺考验思维含量的吧 首先,这个和数位dp是差不多的方法,计算cal(l)-cal(l-1): ...
- 关于MyEclipse不停报错multiple problems have occurred 或者是内存不足 的解决办法
这是因为 worksapace与svn代码不一样,要更新! 一更新就好了,困扰死我了,卧槽,搞了2个小时,难怪svn一提交就卡死人,原来还就是svn的问题,更新一下就行.
- Hibernate配置过程可能发生的问题及解决方法
1.问题:Exception in thread "main" java.lang.NoClassDefFoundError: org/dom4j/DocumentExceptio ...
- css叠加原则,就近原则
<html><head lang="en"> <meta charset="UTF-8"> <title>< ...
- 浏览器兼容问题 chrome iframe location href
报了个错 var dt2=new Date(d2Arr[0],d2Arr[1],d2Arr[2]); if(dt1>dt2){//比较日期 alert("开始日期不能晚于结束日期!&q ...