hdu 4269 Defend Jian Ge
#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 ;
}
题意是模拟三种装备的购买和合成,需要注意的是:
hdu 4269 Defend Jian Ge的更多相关文章
- 2012年长春网络赛(hdu命题)
为迎接9月14号hdu命题的长春网络赛 ACM弱校的弱菜,苦逼的在机房(感谢有你)呻吟几声: 1.对于本次网络赛,本校一共6名正式队员,训练靠的是完全的自主学习意识 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 ...
- 【HDU】3516 Tree Construction
http://acm.hdu.edu.cn/showproblem.php?pid=3516 题意:平面n个点且满足xi<xj, yi>yj, i<j.xi,yi均为整数.求一棵树边 ...
- HDU 4031 Attack(线段树/树状数组区间更新单点查询+暴力)
Attack Time Limit: 5000/3000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Others) Total Sub ...
- 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 ...
- HDU 1403 Longest Common Substring(后缀数组,最长公共子串)
hdu题目 poj题目 参考了 罗穗骞的论文<后缀数组——处理字符串的有力工具> 题意:求两个序列的最长公共子串 思路:后缀数组经典题目之一(模版题) //后缀数组sa:将s的n个后缀从小 ...
- 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 ...
- 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 ...
- HDU 4280 Island Transport(网络流)
转载请注明出处:http://blog.csdn.net/u012860063 题目链接:pid=4280">http://acm.hdu.edu.cn/showproblem.php ...
随机推荐
- 转载.怎样在Quartus II中转化HDL文件为bsf文件?
步骤1 新建或打开Quartus II工程,用QII自带文本编辑器打开HDL文件. 图1 用QII自带的文本编辑器打开HDL文件 步骤2 选择File>Create / Update>Cr ...
- haproxy中两个常用的宏
list_for_each(pos, head) pos.head 都为list类型 一般来说,head是list的虚拟头,依次取list上的各个节点 container_of(ptr, type, ...
- 常用map总结
Map map = new HashMap(); Iterator it = map.entrySet().iterator(); while (it.hasNext()) { Map.Entry e ...
- PhantomJS 一个隐形的浏览器
下载地址: http://phantomjs.org/download.html 使用方法: 下载压缩包解压出来找到phantomjs.exe 放到python的根目录下
- 1039 Course List for Student
题意:给出K门课程(编号1~K)以及报名该课程的学生,然后有N个学生查询,对于每一个查询,输出该学生所报的相关课程编号,且要求编号按增序输出. 思路:题目不难,解析略.(本来用map直接映射,用STL ...
- thinkphp中配置信息的二维数组设置与使用
有时候配置信息是二维数组 1.配置 <?php return array ( // 阿里大鱼短信配置 'dayu_appkey'=>'xxx', 'dayu_secretKey'=> ...
- MFC学习(七) 单文档程序
1 MFC单文档程序的主要类 (1)文档类(Document) 即应用程序处理的数据对象,文档一般从 MFC 中 CDocument 中派生.CDocument 类用于相应数据文件的读取以及存储 Cv ...
- Linux - 目录结构及文件操作
根目录 “/”:Linux 系统中最高层的目录 这个就是根目录 用 / 表示根目录 bin 目录:存放可执行文件 bin 目录下的文件都是平常使用的命令 在 Linux 系统中,一切都是文件 sbin ...
- MVC原理图解
注解: 视图中通过Action方法向控制器请求数据 控制器通过view()方法向视图呈现数据
- url的进行传参拼接
在项目中会遇到把这一个页面的参数传到下一页里面,这里我在项目中用到一个例证(大神就绕过吧嘻嘻):url: '/pages/buy/submitOrder/submitOrder?sku_id=' + ...