例题6-21 uva506 System Dependencies 模拟
来源:互联网 发布:windows经典桌面壁纸 编辑:程序博客网 时间:2024/05/17 07:22
题目链接:https://vjudge.net/problem/UVA-506
Code:
#include <bits/stdc++.h>using namespace std;const int maxn = 1e5+666;map<string,int>mp;map<int,string>lis;int status[maxn];std::vector<int> depend[maxn]; std::vector<int> depended[maxn];std::vector<int> installed;int cnt = 0;int getid( string s ){if( mp.count(s) ) return mp[s];else{mp[s] = ++cnt ;lis[cnt] = s;return cnt;}}void INSTALL( int u , bool lim ){if( status[u] && lim ) {cout << " " << lis[u] << " is already installed." << endl;return ;}if( status[u] ) return ;for( int i = 0 ; i < depend[u].size() ; i ++ ){INSTALL( depend[u][i] , false );}cout << " Installing " << lis[u] << endl;status[u] = ( lim ? 1 : 2 );installed.push_back(u);} bool need( int u ){for( int i = 0; i < depended[u].size() ; i ++ )if( status[depended[u][i]] ) return true;return false;}void REMOVE( int u , bool lim ){if( lim && !status[u] ) {cout << " " << lis[u] << " is not installed." << endl; return;}if( ( lim || status[u] == 2 ) && !need(u) ){status[u] = 0;installed.erase( remove(installed.begin(),installed.end(),u) ,installed.end() );cout << " Removing " << lis[u] << endl;for( int i = 0 ; i < depend[u].size() ; i++ )REMOVE( depend[u][i] ,false ) ;return ;}if( lim ) cout << " " << lis[u] << " is still needed." << endl;}int main(){//freopen("506.txt","r" , stdin);string op;memset(status,0,sizeof(status));while( getline(cin , op) ){cout << op << endl;if( op == "END" ) break;stringstream ss(op);string s1 , s2;ss >> s1;if( s1[0] == 'I' ){while( ss >> s2)INSTALL( getid(s2) , true );}else if( s1[0] == 'D' ){ss >> s2;int item = getid(s2);string s3; while( ss >> s3 ){int id = getid(s3);depend[item].push_back(id);depended[id].push_back(item);}}else if( s1[0] == 'R' ){ss >> s2 ;REMOVE(getid(s2),true);}else if( s1[0] == 'L' ) {for( int i = 0 ; i < installed.size() ; i++ ){cout << " " << lis[installed[i]] << endl;}}}return 0;}
阅读全文
0 0
- 例题6-21 uva506 System Dependencies 模拟
- UVA506 System Dependencies(模拟)
- 例题6-21 系统依赖(System Dependencies, ACM/ICPC World Finals 1997, UVa506)
- UVa506 - System Dependencies
- UVa 506 - System Dependencies(模拟)
- UVa 506 - System Dependencies
- 506 - System Dependencies
- 506 - System Dependencies
- Uva - 506 - System Dependencies
- UVa #11400 Lighting System Design (例题9-6)
- 例题9-6 UVa11400 Lighting System Design(DP)
- 例题6-1 并行程序模拟 UVa210 双端队列
- 例题6-5 UVA12657 双向链表模拟
- 例题6-1:并行程序模拟(deque的使用)
- make snod (make system no dependencies)
- make snod (make system no dependencies)
- 例题 6
- 例题6
- 共享快递柜方案有哪些开发要多久
- [BFS] HDU 3533
- Java消息队列任务的平滑关闭
- 基于Camshift道路检测(改),基于划定框的匹配
- unity 断点续传
- 例题6-21 uva506 System Dependencies 模拟
- 一、数组
- centos7—raid
- HDU-2019(数列有序!)(逗号运算符和逻辑运算符)
- android资源
- Spring 注解概览
- 「Deep Learning」Spatial Transformer Networks
- intellij的高效使用快捷键
- Python中画图时候的线类型