第26次CCF计算机软件能力认证

第26次CCF计算机软件能力认证

第二题(更新)

100分代码

寻宝!大冒险!

#include <bits/stdc++.h>
using namespace std;
int s[55][55];
map<pair<int, int>, int>tree;
int main(){
    int n, L, S;
    cin >> n >> L >> S;
    for(int i=0; i<n; i++){
        int x,y;
        cin >> x >> y;
        tree[{x, y}] = 1;
    }
    for(int i=0; i<=S; i++){
        for(int j=0; j<=S; j++){
            cin >> s[S-i][j];
        }
    }
    int ans=0;
    for(auto it=tree.begin(); it!=tree.end(); it++){
        int x = it->first.first;
        int y = it->first.second;
        int flag=0;
        if(x+S>L || y+S>L)continue;
        for(int i=0; i<=S; i++){
            for(int j=0; j<=S; j++){
                if((s[i][j] && !tree.count({x+i, y+j})) || (!s[i][j] && tree.count({x+i, y+j}))){
                    flag=1;
                }
            }
        }
        if(!flag)ans++;
    }
    cout << ans;
}

第三题

角色授权
题目
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

70分代码

写的可能有些繁琐,后面三个样例超时了

#include <bits/stdc++.h>
using namespace std;
struct Role{
	string name;
	vector<string>ops;
	vector<string>res_k;
	vector<string>res; 
};
map<string, Role>role_con;
map<string, vector<string> >user_con;
int main(){
	int n,m,q;
	cin >> n >> m >> q;
	for(int i=0; i<n; i++){
		Role role;
		string name;
		cin >> name;
		role.name = name;
		int nv;
		cin >> nv;
		for(int j=0; j<nv; j++){
			string ops;
			cin >> ops;
			role.ops.push_back(ops);
		}
		int no;
		cin >> no;
		for(int j=0; j<no; j++){
			string res_k;
			cin >> res_k;
			role.res_k.push_back(res_k);
		}
		int nn;
		cin >> nn;
		for(int j=0; j<nn; j++){
			string res;
			cin >> res;
			role.res.push_back(res);
		}
		role_con[name] = role;
	}
	
	for(int i=0; i<m; i++){
		string name;
		cin >> name;
		int ns;
		cin >> ns;
		char t;string user;
		for(int j=0; j<ns; j++){
			cin >> t >> user;
			user_con[user].push_back(name);
		}
	}
	while(q--){
		string user;
		cin >> user;
		int ng;
		cin >> ng;
		vector<string>zu;
		for(int i=0; i<ng; i++){
			string zuname;
			cin >> zuname;
			zu.push_back(zuname);
		}
		zu.push_back(user);
		string ops,res_k,res;
		cin >> ops >> res_k >> res;
		int flag=0;
		for(auto user : zu){
			for(auto r_name : user_con[user]){
				Role role = role_con[r_name];
				for(auto _ops : role.ops){
					if(_ops==ops || _ops=="*"){
						for(auto _res_k : role.res_k){
							if(_res_k == res_k||_res_k=="*"){
								if(role.res.size()==0){
									flag=1;
									break;
								}
								for(auto _res : role.res){
									if(_res == res){
										flag=1;
										break;
									}
								}
							}
							if(flag)break;
						}
					}
					if(flag)break;
				}
			}
		}
		cout << flag << endl; 
	}
}
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值