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

【题意】

在这里输入题意

【题解】

记录每个物品它的依赖有哪些,以及它被哪些东西依赖就可以了。
显式安装的东西不能被隐式删除删掉(就是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;
}

【例题 6-21 UVA - 506】System Dependencies的更多相关文章

  1. 【STL+模拟】UVa 506 - System Dependencies

    System Dependencies  Components of computer systems often have dependencies--other components that m ...

  2. UVA 506 System Dependencies(模拟 烂题)

    https://vjudge.net/problem/UVA-506 题目是给出了五种指令,DEPEND.INSTALL.REMOVE.LIST.END,操作的格式及功能如下: DEPEND item ...

  3. Uva - 506 - System Dependencies

    模拟题,注意显示安装和隐式安装,显示安装的必须显示显示删除.把名字转化为整数维护.其他注意都注释了.输入稍微多一下,题目不是很麻烦. AC代码: #include <iostream> # ...

  4. UVa 506 System Dependencies (细节问题)

    题意:输入几种指令,让你进行模拟操作,指令如下: DEPEND item1 item2 (item3 ...) 安装item1需要先安装item2(.item3……) INSTALL item1 安装 ...

  5. Learning ROS: Managing System dependencies

    Download and install the system dependencies for turtlesim: roscd turtlesim cat package.xml rosdep i ...

  6. (高精度运算4.7.21)UVA 10106 Product(大数乘法)

    package com.njupt.acm; import java.math.BigInteger; import java.util.Scanner; public class UVA_10106 ...

  7. 2016.6.21 -Dmaven.multiModuleProjectDirectory system propery is not set,Check $M2_HOME environment variable and mvn script match.

    eclipse中使用maven插件的时候,运行run as maven build的时候报错: -Dmaven.multiModuleProjectDirectory system propery i ...

  8. Uva 11077 Find the Permutations [置换群 DP]

    题意: 给定$n$和$k$,问有多少排列交换$k$次能变成升序 $n \le 21$ $uva$貌似挂掉了$vjudge$上一直排队 从某个排列到$1,2,...,n$和从$1,2,...,n$到某个 ...

  9. Java 常用对象-System类

    2017-11-02 21:41:06 System类:System 类包含一些有用的类字段和方法.它不能被实例化. *常用方法 public static void gc() 运行垃圾回收器. 调用 ...

随机推荐

  1. 虚拟摄像头vivi的测试(二)

    (前一部分的基础操作来源于作者:LingXiaokai 的 Ubuntu 9.10 下如何使用笔记本摄像头以及虚拟摄像头vivi的测试) 自己仅对实际操作中需要注意的点进行阐述 一.先在Ubuntu ...

  2. 【hiho39】二分·归并排序之逆序对

    近期申请了微软的暑假实习,4号就要在线笔试了,在线測试系统用的是http://hihocoder.com/,今天试手做了一道题. [题目] 原题链接:http://hihocoder.com/cont ...

  3. vim-normal多行操作命令的使用

    命令行命令-<:normal>这个命令可以重复上一个操作.他其实就跟.命令的效果查不到.不同的是,他可以把.的效果,作用于你用可视模式下的多行.例如,如果你想在下面的文字里在每一行加一个; ...

  4. JavaScript笔记(5)

    1.return 跳出当前函数 返回一个结果 <script> //return可以跳出当前函数 所以return写在函数的最后一行 function out() { return fun ...

  5. CMDB学习之三数据采集

    判断系统因为是公用的方法,所有要写基类方法使用,首先在插件中创建一个基类 将插件文件继承基类 思路是创建基类使用handler.cmd ,命令去获取系统信息,然后进行判断,然后去执行 磁盘 ,cpu, ...

  6. WIN8.1的安装和打开"这台电脑"速度很慢的解决办法

    WIN8.1的安装和打开"这台电脑"速度很慢的解决办法 对于非服务器用的电脑,如果电脑的内存在2G或更高,首推的操作系统是 WINDOWS8.1 64位企业版,用了就知道,没有比这流畅懂事的操作系统. ...

  7. onblur 对象失去焦点事件

    onblur 对象失去焦点事件 一.总结 1.几乎所有的控件都支持onblur事件 二.简介 onblur 事件 Event 对象 定义和用法 onblur 事件会在对象失去焦点时发生. 语法 onb ...

  8. 5.使用SOAP的XML消息传递

    转自:https://blog.csdn.net/u014066037/article/details/51724658 使用SOAP的XML消息传递的简易流程图: 详细步骤如下: (1)服务请求者的 ...

  9. Linux架设Jsp环境

    本文已发表在2010年<网管员世界> 650) this.width=650;" onclick="window.open("http://blog.51ct ...

  10. 用C#生成随机中文汉字验证码的基本原理

    前几天去申请免费QQ号码,突然发现申请表单中的验证码内容换成了中文,这叫真叫我大跌眼镜感到好笑,Moper上的猫儿们都大骂腾讯采用中文验证码.^_^  我不得不佩服腾讯为了防止目前网络上横行的QQ号码 ...