ccfcsp-202206(1、2、3)

2024-09-08 13:44
文章标签 ccfcsp 202206

本文主要是介绍ccfcsp-202206(1、2、3),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

202206-1 归一化处理

#include <bits/stdc++.h>
using namespace std;
int main() {int n;cin >> n;vector<double> vec(n);double ave = 0;for(int i = 0; i < n; i++){cin >> vec[i];ave += vec[i];}ave /= n;double vari = 0;for(int i = 0; i < n; i++){vari += (vec[i] - ave) * (vec[i] - ave);}vari /= n;for(int i = 0; i < n; i++){cout << (vec[i] - ave) / sqrt(vari) << endl;}return 0;
}

202206-2 寻宝!大冒险!

#include <bits/stdc++.h>
using namespace std;int main() {int n,l,s;cin >> n >> l >> s;set<pair<int,int>> mapset;set<pair<int,int>> treaset;vector<vector<int>> vec(s + 1,vector<int>(s + 1, 0));for(int i = 0; i < n; i++){int x,y;cin >> x >> y;mapset.insert({x,y});}for(int i = s; i >= 0; i--){for(int j = 0; j <= s; j++){cin >> vec[i][j];if(vec[i][j] == 1)treaset.insert({i,j});}}int ans = 0;for(auto it : mapset){if(it.first + s > l || it.second + s > l)//边界判断continue;int flag = 1;for(int i = 0; i <= s; i++){for(int j = 0; j <= s; j++){if(vec[i][j] == 1){if(mapset.find({i + it.first,j + it.second}) == mapset.end()){flag = 0;break;}}else{if(mapset.find({i + it.first,j + it.second}) != mapset.end()){flag = 0;break;}}}}if(flag)ans++;}cout << ans;return 0;
}

202206-3 角色授权

#include <bits/stdc++.h>
using namespace std;struct User{string username;unordered_set<string> mani_lst;unordered_set<string> res_type;unordered_set<string> res_name;
};int check(const User& chr, const string& mani, const string& type, const string& name){if (chr.mani_lst.count(mani) == 0 && chr.mani_lst.count("*") == 0)return 0;if (chr.res_type.count(type) == 0 && chr.res_type.count("*") == 0)return 0;if (chr.res_name.count(name) == 0 && !chr.res_name.empty())return 0;return 1;
}int main(){int n, m, q;cin >> n >> m >> q;map<string, User> role;for (int i = 0; i < n; i++){string chr;User chr_info;cin >> chr;int nv;cin >> nv;for (int iv = 0; iv < nv; iv++){string mani;cin >> mani;chr_info.mani_lst.insert(mani);}int no;cin >> no;for (int io = 0; io < no; io++){string type;cin >> type;chr_info.res_type.insert(type);}int nn;cin >> nn;for (int in = 0; in < nn; in++){string name;cin >> name;chr_info.res_name.insert(name);}role.insert({chr, chr_info});}multimap<string, string> rel_u;multimap<string, string> rel_g;for (int i = 0; i < m; i++){string chr;int ns;cin >> chr >> ns;for (int is = 0; is < ns; is++){string type, user, group;cin >> type;if (type == "u"){cin >> user;rel_u.insert(make_pair(user, chr));}else{cin >> group;rel_g.insert(make_pair(group, chr));}}}for (int i = 0; i < q; i++){string id, mani, type, name;int ng;cin >> id >> ng;string gr_lst[405];for (int ig = 0; ig < ng; ig++)cin >> gr_lst[ig];cin >> mani >> type >> name;auto range_u = rel_u.equal_range(id);for (auto it = range_u.first; it != range_u.second; it++){const string& rolename = it->second;const User& temp = role.find(rolename)->second;if (check(temp, mani, type, name) == 1){cout << 1 << endl;goto ending;}}for (int ig = 0; ig < ng; ig++){auto range_g = rel_g.equal_range(gr_lst[ig]);for (auto it = range_g.first; it != range_g.second; it++){const string& rolename = it->second;const User& temp = role.find(rolename)->second;if (check(temp, mani, type, name) == 1){cout << 1 << endl;goto ending;}}}cout << 0 << endl;ending:continue;}return 0;
}

这篇关于ccfcsp-202206(1、2、3)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1148270

相关文章

ccfcsp-202209(1、2、3)

202209-1 如此编码 #include <bits/stdc++.h>typedef long long ll;using namespace std;int main(){ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);int n,m;cin >> n >> m;vector<ll> a(n,0);vector<ll> b(n,0

ccfcsp-202212(1、2、3)

202212-1 现值计算 #include <bits/stdc++.h>using namespace std;int main(){ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);int n;double i;cin >> n >> i;vector<double> money(n + 1);double res = 0;for(in

【CSP:202206-2】寻宝!大冒险!(Java)

题目链接 202206-2 寻宝!大冒险! 题目描述 求解思路 哈希集合:由于L的数据范围较大,我们通过矩阵存储整个地图并不现实。因此,可以将每个点的信息存放在一个哈希集合中,根据藏宝图上的点去判断能否和集合里边的点对应上。解题思路: 创建一个Point类来存放点的数据,因为需要用到哈希集合,所以重写equals方法和hashCode方法。map数组存放藏宝图的坐标。在进行遍历时

ccfcsp-202305(1、2、3)

202305-1 重复局面 #include <bits/stdc++.h>using namespace std;int main() {ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);int n;cin >> n;unordered_map<string, int> mp;string str, s;while(n--){str = "

202206青少年软件编程(Python)等级考试试卷(四级)

第 1 题 【单选题】 有如下 Python 程序, 包含 lambda 函数, 运行该程序后, 输出的结果是? ( ) g = lambda x,y:x*yprint(g(2,3)) A :2 B :3 C :6 D :8 正确答案:C 试题解析: g = lambda x, y: x*y, lambda 函数返回参数 x 和 y 的积, 因此选 C。 第 2 题 【单选题】

202206青少年软件编程(Python)等级考试试卷(一级)

第 1 题 【单选题】 在Python编辑器中写好程序代码后,在Run菜单中,下列哪个命令可以用来执行程序?( ) A :Check Module B :Run Module C :Python shell D :任意一个都可以 正确答案:B 试题解析: 第 2 题 【单选题】 中国电子学会组织来自全国各地的学生共计90人参加人工智能活动,按参加学生名单顺序,每 10个人一排,若想

2024 ccfcsp认证打卡 2022 12 01 现值计算

import java.util.Scanner;public class FinancialFormula {public static void main(String[] args) {Scanner scanner = new Scanner(System.in);final int N = 1010; // 定义数组大小int n = scanner.nextInt(); //

2024 ccfcsp认证打卡 2023 03 02 垦田计划

import java.util.*;public class Main {public static void main(String[] args) {Scanner input = new Scanner(System.in);int N = 100100; // 定义一个较大的常数Nlong[] t = new long[N]; // 存储任务的耗时long[] c = new l

CCF-CSP真题202206-2《寻宝!大冒险!》

题目背景 暑假要到了。可惜由于种种原因,小 P 原本的出游计划取消。失望的小 P 只能留在西西艾弗岛上度过一个略显单调的假期……直到…… 某天,小 P 获得了一张神秘的藏宝图。 问题描述 西西艾弗岛上种有 n 棵树,这些树的具体位置记录在一张绿化图上。 简单地说,西西艾弗岛绿化图可以视作一个大小为 (L+1)×(L+1) 的 01 矩阵 A, 地图左下角(坐标 (0,0))和右上角(坐标

2024 ccfcsp认证打卡 2023 09 02 坐标变换(其二)

202309-2 坐标变换(其二) 题解1题解2区别第一种算法(使用ArrayList存储操作序列):数据结构:操作序列处理: 第二种算法(使用两个数组存储累积结果):数据结构:操作序列处理: 对比效率简洁性可读性 题解1 import java.util.ArrayList;import java.util.Scanner;public class Main {pu