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

【题意】

在这里输入题意

【题解】

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

    emmmm其实没有接触过weex ,了解一番发现有很多坑,有很多基于weex改良后的框架,比如weexplus等等,基本不用踩多少坑.经过几天的深思熟虑我觉得还是去踩坑,毕竟踩完坑才能真正的了解嘛 w ...

  2. 学习《人人都是产品经理2.0:写给泛产品经理》高清中文PDF+苏杰(作者)

    <人人都是产品经理2.0--写给泛产品经理>将从人开始,以人结束,中间说事,以一个产品从无到有的过程为框架--想清楚.做出来.推出去,外加一章综合案例.其中,最重要的想清楚.做出来.推出去 ...

  3. jQuery判断字符串是否含有中文字符

    //判断字符串是不是中文String.prototype.isChinese = function () {    var reg = /[^\x00-\xff]/ig;//判断是否存在中文和全角字符 ...

  4. 对比了解Grafana与Kibana的关键差异

    对比了解Grafana与Kibana的关键差异 http://www.infoq.com/cn/articles/grafana-vs-kibana-the-key-differences-to-kn ...

  5. qwt的安装和移植-

    目须要依据实时数据绘制出图表,因此我们找到了qwt库.这个库是一个绘制图表,曲线图,柱状图的统计图标. . .. 以下我们就具体解说一下这个库在Larm上的编译和移植 qwt介绍 QWT,全称是Qt ...

  6. vim 技巧之用宏命令批量处理文件

    今天遇到了一种情况,就是我需要同时修改34个文件中的某些字符串的内容,如果一个个打开需改的话,那也太麻烦了.后来就想着能不能通过vim的宏命令来修改呢?现在就总结下关于宏在文件列表中的应用1.首先,我 ...

  7. .net运行项目的几种形式

    1.通过配置IIS 2.通过VS运行项目 3.发布到测试服务器 不同于PHP的发布,直接把相关的类文件传入ftp即可. .net的发布是编译好dll文件,将dll文件传入即可. 比如改了某个文件,就把 ...

  8. js设计模式--------基本概念的理解

    1.闭包,前面已经说过,这里不再做说明 2.封装    对于JS而言,他不像java一样存在私有,公有 ,可以让对象在一些细节方面存在差异,降低他们的耦合程度,对数据做一些约束,我们可以更容易调试,封 ...

  9. css3的新特性选择器-------属性选择器

    自己学css的时候比较乱,这次趁着复习把css3的新特性选择器和css2以前不怎么用的选择器做一个总结 <div id="parent"> <p>I'm a ...

  10. KnockOut下的离开检测

    <input type="text" class="form-control" data-bind="event:{ blur:$root.ch ...