#include <cctype>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
using namespace std;
#define PB push_back
#define MP make_pair
typedef vector<pair<string,int> > VP;
vector<string> mixture;
VP backpack;
map<string, VP>recipe;
map<string,int> value,state,type,cost;
int gold;
inline void init(void)
{
gold=;
backpack.clear();
recipe.clear();
mixture.clear();
value.clear();
state.clear();
type.clear();
cost.clear();
}
inline VP get_recipe(void)
{
int cnt;
string line,item;
stringstream ss;
ss.clear();
getline(cin,line);
ss<<line;
VP res;
while(ss>>item)
{
if(!islower(item[])) continue;
ss>>cnt;
res.PB(MP(item,cnt));
}
return res;
}
int get_value(string s)
{
int res=;
VP tmp = recipe[s];
for(size_t i=; i<tmp.size(); i++)
{
if(value.find(tmp[i].first)==value.end())
res+=get_value(tmp[i].first)*tmp[i].second;
else res+=value[tmp[i].first]*tmp[i].second;
}
return res;
}
inline void read(int n,int t)
{
string item;
for(int i=,price; i<n; i++)
{
cin>>item>>price;
value[item]=price;
type[item]=t;
}
}
inline void read_and_cal(int n)
{
string item;
for(int i=,price; i<n; i++)
{
cin>>item>>price;
cost[item]=price;
recipe[item]=get_recipe();
mixture.PB(item);
type[item]=;
}
for(int i=; i<n; i++)
{
item=mixture[i];
value[item]=cost[item]+get_value(item);
}
}
inline int get_num(string s)
{
int res=;
for(size_t i=; i<s.size(); i++) res=res*+(s[i]&);
return res;
}
inline void update(void)
{
backpack.clear();
for(map<string,int>::iterator it=state.begin(); it!=state.end(); it++)
{
if(type[it->first]==) backpack.PB(MP(it->first,it->second));
else
{
for(int i=; i<(it->second); i++)
backpack.PB(MP(it->first,));
}
}
}
inline void get_item(string s)
{
if(type[s]==)
{
if(cost[s]>gold) return;
VP tmp=recipe[s];
for(VP::iterator it=tmp.begin(); it!=tmp.end(); it++)
if(state[(*it).first]<(*it).second) return;
for(VP::iterator it=tmp.begin(); it!=tmp.end(); it++)
{
state[(*it).first]-=(*it).second;
if(!state[(*it).first]) state.erase((*it).first);
}
gold-=cost[s];
}
else
{
if(value[s]>gold || backpack.size()==) return;
gold-=value[s];
}
state[s]++;
update();
}
inline void sell_item(string s)
{
if(state.find(s)==state.end()) return;
if(type[s]==)
{
gold+=value[s]*state[s];
state.erase(state.find(s));
}
else
{
gold+=value[s];
if(state[s]==) state.erase(state.find(s));
else state[s]--;
}
update();
}
inline void output(int c)
{
cout<<"Case "<<c<<":\n"<<gold<<'\n'<<backpack.size()<<'\n';
sort(backpack.begin(),backpack.end());
for(VP::iterator it=backpack.begin(); it!=backpack.end(); it++)
cout<<(*it).first<<": "<<(*it).second<<'\n';
cout<<'\n';
}
int main(void)
{
int n1,n2,n3,m;
string opt,arg;
for(int cas=; cin>>n1; cas++)
{
init();
read(n1,);
cin>>n2;
read_and_cal(n2);
cin>>n3;
read(n3,);
for(cin>>m; m--;)
{
cin>>opt;
arg=opt.substr(,opt.size()-);
if(isdigit(opt[])) gold+=get_num(arg);
else if(opt[]=='+') get_item(arg);
else sell_item(arg);
}
output(cas);
}
return ;
}

题意是模拟三种装备的购买和合成,需要注意的是:

1.当物品栏满时只能合成装备,并且合成后的装备也要占一个,所以只要合成卷轴就能合成的装备只有在当前的物品栏没有满时才能合成。
2.消耗装备在物品栏满时无法再购买,即使物品栏里有相同的消耗装备,因为题意默认先购买再合并,在这点上我果断被坑了。
3.合成装备的“原料”只能是基本装备和合成装备。
4.除消耗装备外其它装备每个都要占一个物品栏。

hdu 4269 Defend Jian Ge的更多相关文章

  1. 2012年长春网络赛(hdu命题)

    为迎接9月14号hdu命题的长春网络赛 ACM弱校的弱菜,苦逼的在机房(感谢有你)呻吟几声: 1.对于本次网络赛,本校一共6名正式队员,训练靠的是完全的自主学习意识 2.对于网络赛的群殴模式,想竞争现 ...

  2. HDU 4283---You Are the One(区间DP)

    题目链接 http://acm.split.hdu.edu.cn/showproblem.php?pid=4283 Problem Description The TV shows such as Y ...

  3. 【HDU】3516 Tree Construction

    http://acm.hdu.edu.cn/showproblem.php?pid=3516 题意:平面n个点且满足xi<xj, yi>yj, i<j.xi,yi均为整数.求一棵树边 ...

  4. HDU 4031 Attack(线段树/树状数组区间更新单点查询+暴力)

    Attack Time Limit: 5000/3000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others) Total Sub ...

  5. HDU 4031 Attack(离线+线段树)(The 36th ACM/ICPC Asia Regional Chengdu Site —— Online Contest)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4031 Problem Description Today is the 10th Annual of ...

  6. HDU 1403 Longest Common Substring(后缀数组,最长公共子串)

    hdu题目 poj题目 参考了 罗穗骞的论文<后缀数组——处理字符串的有力工具> 题意:求两个序列的最长公共子串 思路:后缀数组经典题目之一(模版题) //后缀数组sa:将s的n个后缀从小 ...

  7. hdu 4739 Zhuge Liang's Mines 随机化

    Zhuge Liang's Mines Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.p ...

  8. HDU 5889 Barricade 【BFS+最小割 网络流】(2016 ACM/ICPC Asia Regional Qingdao Online)

    Barricade Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total S ...

  9. HDU 4280 Island Transport(网络流)

    转载请注明出处:http://blog.csdn.net/u012860063 题目链接:pid=4280">http://acm.hdu.edu.cn/showproblem.php ...

随机推荐

  1. phpwind主要表结构的研究随笔[1]

    最近计划做一个新闻网站,前端打算用成熟的CMS搭建,后台是mongodb+mysql做数据过滤容器和最终数据存储,选型CMS如下: dedecms:国内某知名cms,以前用过,功能强大,网上资料资料很 ...

  2. 2 分支语句——《Swift3.0 从入门到出家》

    2 分支语句 当程序面临多个选择,每一个选择都会执行不同的代码块,这个时候就要使用分支语句.常见的分支语句有: if 选择语句:if... if…else if…elseif…else if是现实生活 ...

  3. Maven依赖调解

    引用来自maven实战中的一段话.

  4. 为什么我的 FastAdmin 慢?

    为什么我的 FastAdmin 慢? 排查流程 询问 demo.fastadmin.net 是否慢,官方 demo 安装了 80% 的插件. 开发时一般都是打开 debug 配置,上线要把 debug ...

  5. 有关Botton的用法(二)

    关于设置listener监听onClicked事件的步骤分析 Steps: 1.tell android you are interested in listening to a button cli ...

  6. shell中字体变色

    在linux中给字体使用数字代码变色 字体颜色代码:重置0 ,黑色30,红色31,绿色32,黄色33,蓝色34,洋红35,青色36,浅灰37 效果代码:1m加粗  2m加下划线  5m闪动效果  7m ...

  7. 显示等待 之 text_to_be_present_in_element 判断元素是否有xx 文本信息 用法

  8. 【转】 Pro Android学习笔记(八八):了解Handler(2):什么是Handler

    文章转载只能用于非商业性质,且不能带有虚拟货币.积分.注册等附加条件.转载须注明出处:http://blog.csdn.net/flowingflying/ 之前我们有一篇很好的博文<Andro ...

  9. PHPCMS分页原理

    调用很方便,使用listinfo方法,如果小于1页不会返回分页字符串 $page = $_GET['page'] ? intval($_GET['page']) : '1'; $products = ...

  10. Xdebug日志文件不显示

    Xdebug是一个很强大的调试php的软件,安装也很简单. 1.php_xdebug.dll 放入php目录下的ext文件中 2.php.ini中开启 [Xdebug] extension = &qu ...