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 ...
随机推荐
- 转:lr_eval_string函数的用法解析
在LR中,C的变量和LR的参数是不一样的. 任何C的变量都不能被LR的函数直接调用. 应该用lr_eval_string来取值. 比如{NewParam}(LR中参数化的变量)直接用这个引用是没有问题 ...
- PAT (Advanced Level) 1101. Quick Sort (25)
树状数组+离散化 #include<cstdio> #include<cstring> #include<cmath> #include<map> #i ...
- ecshop后台增加模块菜单项详细教程(图文)
有的时候我们会在后台增加新的功能,菜单项是一个程序的入口,是必不可少的,如何在后台增加菜单项呢,大家可以参考下面的教程: 例如:想在后台左侧的菜单栏的"促销管理"下添加一个&q ...
- View与ViewGroup有什么区别?
百度知道:http://zhidao.baidu.com/link?url=B5MFOzDlww8soYqr5CL5FldH4sXD6eumS1XTRn8XEh8gu4mKjQdPkJSLIBt7u_ ...
- c# 执行js的方法
http://www.cnblogs.com/wuhuacong/archive/2010/11/08/1871866.html 为了有效阻止恶意用户的攻击,一般登录都会采用验证码方式方式处理登录,类 ...
- Nginx 502/504 Gateway time-out错误完美解决方案【转发】
在安装完Nginx+PHP-fpm+Mysql后,跑PHP的应用会经常出现504 Gateway Time-out 或者502 Bad Gateway的情况. Nginx 504 Gateway ...
- BAT54C 二极管是如何工作的?
这是一个多电源供电的电路:Vcc是正常供电电源(如5V,由市电变换得到),电压大于(Vcc1-Vf),正常供电时二极管不导通:Vcc1是电池供电电源,当Vcc撤掉时,DD1(上边的二极管)导通,由Vc ...
- 关于自定义jar包(tomcat)的添加
1 鼠标右击工程 选择 properties 或者 Ait + Enter 2 选择Libraries 3 点击Add Library... 4 选择User Library 点击 Next 5 如 ...
- Android平台中实现对XML的三种解析方式
本文介绍在Android平台中实现对XML的三种解析方式. XML在各种开发中都广泛应用,Android也不例外.作为承载数据的一个重要角色,如何读写XML成为Android开发中一项重要的技能. 在 ...
- GB2312转unicode程序(转)
GB2312转unicode程序 #ifndef UNICODE_H #define UNICODE_H #include <string.h> #ifdef __DEFLINUX_ ...