#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. 转发一篇关于django模型详解的一篇好的博客

    http://blog.csdn.net/pipisorry/article/details/45725953

  2. innerHTML和innerText怎么区分

    示例代码:<div id="test"> <span style="color:red">test1</span> test ...

  3. YY一下十年后的自己(转)

    每到年底总是我最焦虑的时候,年龄越大情况越明显.可能越长大越是对 时光的流逝 更有感触,有感触之后就会胡思乱想.所以随手开始写下这篇文章. 人无远虑必有近忧.那么同学呀,你听说过安利么. 一直都有做总 ...

  4. Servlet概念入门

    什么是Servlet Servlet 为创建基于 web 的应用程序提供了基于组件.独立于平台的方法,可以不受 CGI 程序的性能限制.Servlet 有权限访问所有的 Java API,包括访问企业 ...

  5. Excel 2007 打开 UTF-8 编码 CSV 文件的乱码BUG

    http://blog.sina.com.cn/s/blog_6c3b65fd01018dgq.html 打开UTF-8编码的CSV方法: 1) 打开Excel 2007 2) 执行“数据”-> ...

  6. zabbix 触发器 | count 函数

    摘要:确认多次zabbix监控中小编用的最多的是count的这函数,确认多次以减少了很多误告警,提高了运维效率.可以设置连续几次都异常才发出告警,这样一来,只要发出告警基本上就已经确定发生故障了.co ...

  7. new JSONObject()报错

    如果缺少下列依赖包会报错: 1.commons-beanutils-1.7.0.jar 2.commons-collections-3.2.1.jar 3.commons-lang-2.3.jar 4 ...

  8. MVC 控制器之间传值学习——session

    刚接触MVC不久,写的一些代码自己都不忍心看下去.路漫漫其修远兮,宝宝还需努力!之前只用过Session做登录时用户信息的储存,今天对集合类数据做了小小的尝试:利用session在控制器之间传值,以减 ...

  9. xml处理模块

    xml是实现不同语言或程序之间进行数据交换的协议,跟json差不多,但json使用起来更简单,不过,古时候,在json还没诞生的黑暗年代,大家只能选择用xml呀,至今很多传统公司如金融行业的很多系统的 ...

  10. PHP $_SERVER变量

    <?php #测试网址: http://localhost/t/test.php?id=5 //获取域名或主机地址 echo $_SERVER['HTTP_HOST']."<br ...