#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. Git克隆、修改、更新项目,及查看项目地址命令

    第一步:在本地新建一个文件夹,作为本地仓库,如“texzt”,直接打开该文件夹,并单击右键,选择git bash here 则可以直接进入到该文件夹目录下. 第二步:将本地仓库初始化,命令:git i ...

  2. UGUI 分页渐变居中效果

    代码相当冗长,仅作自己记录 在此分页上修改的https://blog.csdn.net/qinyuanpei/article/details/49781133 using UnityEngine;us ...

  3. 学习动态性能表(4)--v$sqltext&v$sqlarea

    学习动态性能表 第四篇-(1)-V$SQLTEXT  2007.5.29 本视图包括Shared pool中SQL语句的完整文本,一条SQL语句可能分成多个块被保存于多个记录内. 注:V$SQLARE ...

  4. 第21篇 ubuntu安装ftp服务器(转载)

    ubuntu安装ftp服务器 1: 安装vsftpd ~$ sudo apt-get install vsftpd ubuntu10.10自己装了,这步省略. 2: 配置vsftpd 2.1 修改vs ...

  5. 第三方引擎应用场景分析--Tokudb,infobright

    TokuDBTokuDB的特色:• Fractal Tree而不是B-Tree• 内部结点不仅有指向父子的指针还有Buffer区,数据写入先写buffer区,FIFO结构,写入只需要顺序添加到Buff ...

  6. linux命令echo和cat比较

    当前主要比较echo 和 cat的重定向功能 1.echo 1 > /proc/xxx 解析: echo 进行重定向的时候,仅仅是将字符"1" 输出到 /proc/xxx文件 ...

  7. cocoa 线程操作

    在Cocoa 中创建线程使用NSThread类的detachNewThreadSelector: toTarget:withObject:方法 NSPort *port1 = [NSPort port ...

  8. VC6编写的Dll调试方法

    Dll工程运行时指定调用exe程序. 关键!!往往被忽略:exe中也一定要指向此调用dll,如果指向不对,什么效果也没有!

  9. JavaScript语言基础-作用域

  10. 02-26C#三级省市区ajax联动控件,利用UpdatePanel,以及页面取值

    第一步:设置界面 <%@ Control Language="C#" AutoEventWireup="true" CodeFile="PCAC ...