UVa506 - System Dependencies
来源:互联网 发布:巨人网络借壳上市过程 编辑:程序博客网 时间:2024/05/16 12:21
#include<iostream>#include<string>#include<map>#include<sstream>#include<vector>#include<algorithm>using namespace std;const int maxn=10000;int cnt,status[maxn];string name[maxn];map<string,int>ids;vector<int> depend[maxn],depend2[maxn],installed;int get_id(string s){ if(ids.count(s)) return ids[s]; name[cnt]=s; return ids[s]=cnt++;}bool needed(int item){ for(int i=0;i<depend2[item].size();++i) if(status[depend2[item][i]]) return true; return false;}void install(int item,bool toplevel){ if(!status[item]){ for(int i=0;i<depend[item].size();i++) install(depend[item][i],false); cout<<" Installing "<<name[item]<<'\n'; status[item]=toplevel?1:2; installed.push_back(item); }}void remove(int item,bool toplevel){ if((toplevel||status[item]==2)&&!needed(item)){ status[item]=0; installed.erase(remove(installed.begin(),installed.end(),item),installed.end()); cout<<" Removing "<<name[item]<<'\n'; for(int i=0;i<depend[item].size();i++) remove(depend[item][i],false); }}int main(){ ios::sync_with_stdio(false); string s,cmd; while(getline(cin,s)){ cout<<s<<'\n'; if(s[0]=='E') break; stringstream ss(s); ss>>cmd; if(cmd[0] == 'L'){ for(int i=0;i<installed.size();++i) cout<<" "<<name[installed[i]]<<'\n'; }else{ int id1,id2; string s1,s2; ss>>s1; id1=get_id(s1); if(cmd[0]=='D'){ while(ss>>s2){ id2=get_id(s2); depend[id1].push_back(id2); depend2[id2].push_back(id1); } } if(cmd[0]=='I') { if(status[id1]) cout<<" "<<s1<<" is already installed.\n"; else install(id1,true); } if(cmd[0]=='R'){ if(!status[id1]) cout<<" "<<s1<<" is not installed.\n"; else if(needed(id1)) cout<<" "<<s1<<" is still needed.\n"; else remove(id1,true); } } } return 0;}
0 0
- UVa506 - System Dependencies
- UVA506 System Dependencies(模拟)
- 例题6-21 uva506 System Dependencies 模拟
- 例题6-21 系统依赖(System Dependencies, ACM/ICPC World Finals 1997, UVa506)
- UVa 506 - System Dependencies
- 506 - System Dependencies
- 506 - System Dependencies
- Uva - 506 - System Dependencies
- make snod (make system no dependencies)
- make snod (make system no dependencies)
- UVa 506 - System Dependencies(模拟)
- Dependencies
- UVa 506 - System Dependencies <图的拓扑序+STL应用>
- ... or one of its dependencies. The system cannot find the file specified... 加载指定dll失败
- 解决maven web项目倒入eclipse不出现Maven Dependencies 和 Java System Library的问题
- Could not load file or assembly 'App_Web_xxxx' or one of its dependencies. The system cannot find the file specified.
- Could not load file or assembly "xxx" or one of its dependencies. The system cannot find the file sp
- Could not load file or assembly 'System.Data.SQLite' or one of its dependencies. An attempt was made
- iOS App提交指南-协议、税务和银行业务
- SlidingMenu使用实例
- eminem
- boost shared_ptr的注意事项记录
- 自己手动实现 KVO(来源:Glow 技术团队博客)
- UVa506 - System Dependencies
- 一站式学习Wireshark(四):网络性能排查之TCP重传与重复ACK
- 蓝天碧水中国梦-高污染企业-纺织业(1)
- OS X下搭建Git服务器建议教程
- 线性素数筛法
- 查看linux 系统 服务器型号
- Java I/O流
- 视频播放入门1
- 玩玩三维重建