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 ...
随机推荐
- 转载 eclipse中的include设置
备注:在10.1版的niosii使用的eclipse中设置的方法是右键->properties->c/c++general->path and symbols->include ...
- ZooKeeper群集安装
4节点Hadoop安装ZooKeeper.环境:CentOS 6.4,Hadoop 2.6.0,ZooKeeper 3.4.6 HostName Hadoop Role myid HDP1 Slave ...
- BZOJ4755:[JSOI2016]扭动的回文串
浅谈\(Manacher\):https://www.cnblogs.com/AKMer/p/10431603.html 题目传送门:https://lydsy.com/JudgeOnline/pro ...
- java.sql.SQLException: No suitable driver
java.sql.SQLException: No suitable driver at java.sql.DriverManager.getDriver(Unknown Source) at com ...
- java代码----求最大值,平均值。。。
总结:方法的返回值----返回的对象到底是什么? package com.a; import java.util.Scanner; //从键盘输入10个数,并输出最大值,最小值,平均值 public ...
- C语言中的未初始化变量的值
C语言中未初始化的变量的值是0么 全局变量 .静态变量初始值为0局部变量,自动变量初始值随机分配 C语言中,定义局部变量时如果未初始化,则值是随机的,为什么? 定义局部变量,其实就是在栈中通过移动栈指 ...
- pandas层级索引
层级索引(hierarchical indexing) 下面创建一个Series, 在输入索引Index时,输入了由两个子list组成的list,第一个子list是外层索引,第二个list是内层索引. ...
- pthread thread mutex synchronous asynchronous communication
设置进程绑定状态的函数pthread_attr_setscopepthread_attr_t 指向属性结构的指针第二个参数 绑定类型 pthread_scope_system()pthread_sco ...
- CSS中盒子垂直居中的常用方法
在前端开发过程中,盒子居中是常常用到的.其中 ,居中又可以分为水平居中和垂直居中.水平居中是比较容易的,直接设置元素的margin: 0 auto就可以实现.但是垂直居中相对来说是比较复杂一些的.下面 ...
- Elasticsearch之插件介绍及安装
ES站点插件(以网页形式展现) 1.BigDesk Plugin (作者 Lukáš Vlček) 简介:监控es状态的插件,推荐![目前不支持2.x] 2.Elasticsearch Head Pl ...