博主原创,转载请注明出处
T2-寻宝!大冒险!
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
set<PII> s, cs;
int n, L, S;
int B[55][55];
int main()
{
scanf("%d%d%d", &n,&L,&S);
int x, y;
for(int i = 1; i <= n; i++){
scanf("%d%d", &x, &y);
s.insert({x, y});
}
for(int i = S; i >= 0; i--){
for(int j = 0; j <= S; j++){
scanf("%d", &B[i][j]);
if(B[i][j] == 1) cs.insert({i, j});
}
}
auto it = s.begin();
int biax, biay;
LL res = 0;
while(it != s.end())
{
if(it->first + S > L || it->second + S > L){
it++;
continue;
}
biax = it->first, biay = it->second;
bool flag = true;
auto i = it , j = cs.begin();
while(j != cs.end() && i != s.end()){
if(!((i->first - biax >= 0) && (i->first - biax <= S) && (i->second - biay >= 0) && (i->second - biay <= S))){
i++;
continue;
}
else if((i->first - biax != j->first) || (i->second - biay != j ->second)) {
flag = false;
break;
}
i++, j++;
}
if(j != cs.end()) flag = false;
else{
while(i != s.end()){
if((i->first - biax >= 0) && (i->first - biax <= S) && (i->second - biay >= 0) && (i->second - biay <= S)){
flag = false;
break;
}
i++;
}
}
if(flag) res ++;
it++;
}
cout << res << endl;
return 0;
}
T3-角色授权
#include <bits/stdc++.h>
using namespace std;
const int N = 5000;
int n, m, q;
struct Role{
string name;
set<string> op;
set<string> res_kind;
set<string> res_name;
}roles[N];
map<string, int> mp;
map<string, vector<int>> permit_user;
map<string, vector<int>> permit_group;
struct User{
string name;
vector<string> group;
};
// role->res
// O(6)
bool judge_role(int idx, string op, string res_k, string res_n)
{
if(!(roles[idx].op.count(op) || roles[idx].op.count("*")))
return false;
if(!(roles[idx].res_kind.count(res_k) || roles[idx].res_kind.count("*")))
return false;
if(roles[idx].res_name.empty() || roles[idx].res_name.count(res_n))
return true;
else return false;
}
// user->deed
bool judge(User& user, string op, string res_k, string res_n)
{
int i;
bool j = false;
for(auto i:permit_user[user.name]){
if(judge_role(i, op, res_k, res_n))
return true;
}
// O(400 * 400 * C)
for(auto g:user.group)
for(auto i:permit_group[g])
if(judge_role(i, op, res_k, res_n))
return true;
return false;
}
void solve()
{
int s;
ios::sync_with_stdio(false);
cin >> n >> m >> q;
string temp;
for(int i = 0; i < n; i++)
{
cin >> roles[i].name >> s;
mp[roles[i].name] = i;
while(s--){
cin >> temp;
roles[i].op.insert(temp);
}
cin >> s;
while(s--){
cin >> temp;
roles[i].res_kind.insert(temp);
}
cin >> s;
while(s--){
cin >> temp;
roles[i].res_name.insert(temp);
}
}
string tp, u_name;
int t;
for(int i = 0; i < m; i++)
{
cin >> temp >> t;
int idx = mp[temp]; // 查到role的索引
while(t--)
{
cin >> tp >> u_name;
if(tp == "u") permit_user[u_name].push_back(idx);
else permit_group[u_name].push_back(idx);
}
}
int ng;
for(int i = 0; i < q; i++)
{
User user;
cin >> user.name >> ng;
for(int j = 0; j < ng; j++)
{
cin >> tp;
user.group.push_back(tp);
}
string op, res_k, res_n;
cin >> op >> res_k >> res_n;
bool flag = judge(user, op, res_k, res_n);
if(flag) puts("1");
else puts("0");
}
}
int main()
{
solve();
return 0;
}