CCF CSP 201612-3 許可權查詢
阿新 • • 發佈:2020-09-10
樣例輸入
3
crm:2
git:3
game
4
hr 1 crm:2
it 3 crm:1 git:1 game
dev 2 git:3 game
qa 1 git:2
3
alice 1 hr
bob 2 it qa
charlie 1 dev
9
alice game
alice crm:2
alice git:0
bob git
bob poweroff
charlie game
charlie crm
charlie git:3
malice game
樣例輸出
false
true
false
2
false
true
false
true
false
直接用多個map去對應過去名字和許可權以及等級
思路蠻簡單的,就注意一些細節,比如多個角色
有相同的許可權取最高,許可權存不存在啊啥的
#include<bits/stdc++.h> #include<string.h> using namespace std; #define rep(i,j,k) for(LL i=(j); i<(k); ++i) #define pb push_back #define PII pair<LL,LL> #define PLL pair<long long, long long> #define ini(a,j) memset(a,j,sizeof a) #define rrep(i,j,k) for(LL i=j; i>=k; --i) #define fi first #define se second #define LL long long #define beg begin() #define end end() #define all(x) x.begin(),x.end() const LL mod= 1e9+7; const unsigned int N = 1e5+10; // all 存的是一個職業對應的許可權等級 // ans 儲存人對應的許可權 map<pair<string, string>, int> all, ans; //p_info存許可權是否的有等級的 map<string, int> p_info; // 對於一個詞 // 有帶等級的直接先升級兩級,防止衝突 // 沒有等級的直接給1,防止對0無法判斷 pair<string, int> split(string s){ //分詞函式 string name=""; int j=0; int ma = 0; if(isdigit(s.back())){ while(s[j]!=':'){ name += s[j]; ++j; } ++j; while(j<s.length()) ma = ma*10+s[j++]-'0'; ma += 2; }else{ name = s; ma = 1; } return make_pair(name, ma); } void solve(string name, string quer){ auto que = split(quer); //先去map中查這個人的許可權是什麼等級 int res = ans[make_pair(name, que.fi)]; int type = p_info[que.fi]; if(!res){ cout<<"false"<<endl; return; } if(que.se==1){ //不帶數字的查詢 if(type==1){ cout<<(res==0 ? "false":"true")<<endl; }else{ cout<<res-2<<endl; } }else{ cout<<(que.se<=res? "true":"false")<<endl; } } int main(int argc, char const *argv[]) { // #define DEBUG #ifdef DEBUG freopen("1.dat","r",stdin); #endif ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int pnum; cin>>pnum; string info; rep(i,0,pnum){ cin>>info; auto info_m = split(info); p_info[info_m.fi]=info_m.se; } // cout<<"............priv......................"<<endl; int num_man; cin>>num_man; rep(i,0,num_man){ string man; int cnt; cin>>man>>cnt; string pp; rep(i,0,cnt){ cin>>pp; auto pp_det = split(pp); // 一個角色擁有的許可權,對於某項也取最高,貌似沒必要 all[make_pair(man, pp_det.fi)] = max(all[make_pair(man, pp_det.fi)], pp_det.se); } } // cout<<"............personal priv......................"<<endl; cin>>num_man; rep(i,0,num_man){ string man; int cnt; cin>>man>>cnt; string pp; rep(i,0,cnt){ cin>>pp; for(auto e:p_info){ //如果多個角色有這個許可權,取最高的 ans[make_pair(man, e.fi)]=max(ans[make_pair(man, e.fi)],all[make_pair(pp,e.fi)]); } } } // cout<<"............Query begin......................"<<endl; int query; cin>>query; string name,quer; while(query--){ cin>>name>>quer; solve(name, quer); } return 0; }