【链接】 我是链接,点我呀:)

【题意】

在这里输入题意

【题解】

记录每个物品它的依赖有哪些,以及它被哪些东西依赖就可以了。
显式安装的东西不能被隐式删除删掉(就是remove item,然后删除item的依赖的过程叫隐式删除,而删除item本身叫显式删除);
而只能被显式删除。
隐式安装的依赖则可以被显式或隐式删除都行。
(显示安装指的是 install item,安装item本身,而安装item的依赖,都称为是隐式的安装)

写个安装和删除的递归函数就好。

样例的答案有误。

remove browser那里应该是先remove tcpip 后remove html.

【代码】

/*
1.Shoud it use long long ?
2.Have you ever test several sample(at least therr) yourself?
3.Can you promise that the solution is right? At least,the main ideal
4.use the puts("") or putchar() or printf and such things?
5.init the used array or any value?
6.use error MAX_VALUE?
*/
#include <bits/stdc++.h>
using namespace std; string s;
map <int,vector <int> > yilai,beiyilai;
map <int,int> status;
map <string,int> dic;
map <int,string> dic2;
vector <int> installed;
string ope;
int tot = 0; void pd(string temp){
if (dic[temp]==0) {
dic[temp] = ++tot;
dic2[tot] = temp;
}
} void ins(int id,bool highest){
if (status[id]==0){
if (yilai.find(id)!=yilai.end()){
vector <int> v = yilai[id];
int len = v.size();
for (int i = 0;i < len;i++){
int x = v[i];
ins(x,0);
}
}
cout << " Installing "<<dic2[id] << endl;
installed.push_back(id);
status[id] = (highest?1:2);
}
} bool need(int x){
if (beiyilai.find(x)!=beiyilai.end()){
vector <int> v = beiyilai[x];
int len = v.size();
for (int i = 0;i < len;i++){
int x = v[i];
if (status[x]) return true;
}
}
return false;
} void dele(int id,bool highest){
if ( !need(id) && (highest || status[id]==2)){
status[id] = 0;
cout << " Removing " << dic2[id] << endl;
installed.erase(remove(installed.begin(),installed.end(),id),installed.end());
if (yilai.find(id)!=yilai.end()){
vector <int> v = yilai[id];
int len = v.size();
for (int i = 0;i < len;i++){
int x = v[i];
if (status[x]) dele(x,0);
}
}
}
} int main(){
#ifdef LOCAL_DEFINE
freopen("F:\\c++source\\rush_in.txt", "r", stdin);
#endif
ios::sync_with_stdio(0),cin.tie(0); while (getline(cin,s)){
yilai.clear(),beiyilai.clear(),
status.clear(),dic.clear();dic2.clear();
installed.clear();
while (s!="END"){
cout << s << endl;
stringstream ss(s);
ss >> ope;
if (ope=="INSTALL"){
string x;
ss >> x;
pd(x);
int y = dic[x];
if (status[y]!=0)
cout <<" "<<x<<" is already installed."<<endl;
else
ins(y,1);
}else if (ope=="REMOVE"){
string x;
ss >> x;
pd(x);
int y = dic[x];
if (status[y]==0)
cout <<" "<<x<<" is not installed."<<endl;
else if (need(y))
cout <<" "<<x<<" is still needed."<<endl;
else{
dele(y,1);
}
}else if (ope=="LIST"){
for (int x:installed){
cout <<" "<<dic2[x]<<endl;
}
}else{
//depend
string x,y;int xx,yy;
ss >> x;
pd(x);xx = dic[x];
while (ss>>y){
pd(y);yy = dic[y];
yilai[xx].push_back(yy);
beiyilai[yy].push_back(xx);
}
}
getline(cin,s);
}
cout << s << endl;
} return 0;
}

最新文章

  1. 通过类名获取spring里的Bean
  2. (五)WebRTC手记Channel概念
  3. MFC MessageBox AfxMessageBox
  4. poj 3667 Hotel(线段树,区间合并)
  5. Mac OS X中打zip包时去除.DS_Store等指定文件
  6. Careercup - Google面试题 - 5085331422445568
  7. java开发命名规范总结
  8. HDU FatMouse&#39;s Speed 基本DP
  9. Cocos2d-iphone 为sprite添加双击的事件响应
  10. Largest Rectangle in Histogram 解答
  11. 开源 iOS 项目分类索引大全
  12. 【Android UI】案例03滑动切换效果的实现(ViewPager)
  13. (简单) POJ 3268 Silver Cow Party,Dijkstra。
  14. XSS跨站脚步攻击及防范
  15. VCC、 VDD、VEE、VSS 电压理解
  16. legend2---开发日志8(thinkphp和vue如何配合才能达到最优)
  17. kubernetes下安装mysql
  18. 学会查看Linux手册页(man文档)
  19. 循序渐进学.Net Core Web Api开发系列【5】:文件上传
  20. Java第三阶段学习(一、IO流------File类)

热门文章

  1. js数组中foEach和map的用法详解 jq中的$.each和$.map
  2. 51nod 编辑距离 + 滚动数组优化
  3. 翻译《虚幻引擎4艺术大师 - 蓝图 III 》 中文版
  4. 洛谷 P3913 车的攻击
  5. 11.2.0.1升级到11.2.0.4报错之中的一个:UtilSession failed: Patch 9413827
  6. 与TCP/IP协议的初次见面(一)
  7. Elasticsearch之REST
  8. c#数据类型格式转换大全
  9. Intellij IDEA 部署Web项目,解决 404 错误
  10. JAVA使用YUI压缩CSS/JS