第22次CCF计算机软件能力认证
第一题:灰度直方图
解题思路:
哈希表即可
#include<iostream>
#include<cstring>using namespace std;const int N = 610;
int a[N];
int n , m , l;int main()
{memset(a , 0 , sizeof a);cin >> n >> m >> l;for(int i = 0;i < n;i ++)for(int j = 0;j < m;j ++){int x;cin >> x;a[x] ++;}for(int i = 0;i < l;i ++)cout << a[i] << " ";return 0;
}
第二题:邻域均值
解题思路:
二维前缀和
#include<iostream>
#include<cstring>using namespace std;const int N = 610;
int s[N][N];
int n , l , r , t;int main()
{memset(s , 0 , sizeof s);cin >> n >> l >> r >> t;for(int i = 1;i <= n;i ++)for(int j = 1;j <= n;j ++){int x;cin >> x;s[i][j] = s[i][j - 1] + s[i - 1][j] - s[i - 1][j - 1] + x;}int res = 0;for(int i = 1;i <= n;i ++)for(int j = 1;j <= n;j ++){int x1 = max(1 , i - r) , y1 = max(1 , j - r);int x2 = min(n , i + r) , y2 = min(n , j + r);int sum = s[x2][y2] - s[x1 - 1][y2] - s[x2][y1 - 1] + s[x1 - 1][y1 - 1];int cnt = (x2 - x1 + 1) * (y2 - y1 + 1);if(sum <= t * cnt) res ++;}cout << res << endl;return 0;
}
第三题:DHCP服务器
解题思路:
认真读题,题目描述的非常清楚更具题目进行求解即可,
#include<iostream>
#include<algorithm>using namespace std;const int N = 1e5 + 10;int n , tdef , tmax , tmin;
string h; // 本机名称struct IP
{int st; // 0表示未分配、1表示待分配、2表示占用、3表示过期string owner; // 未分配状态没有占用者int t; // 待分配和占用状态拥有一个大于零的过期时刻
}ip[N];int get_ip_d(string c)
{for(int i = 1;i <= n;i ++)if(ip[i].owner == c) return i;return 0;
}int get_ip(int state)
{/*若没有,则选取最小的状态为未分配的 IP 地址若没有,则选取最小的状态为过期的 IP 地址*/for(int i = 1;i <= n;i ++)if(ip[i].st == state) return i;return 0;
}void update(string send)
{/*若不是,则找到占用者为发送主机的所有 IP 地址,对于其中状态为待分配的,将其状态设置为未分配,并清空其占用者,清零其过期时刻,处理结束*/for(int i = 1;i <= n;i ++)if(ip[i].owner == send) {if(ip[i].st == 1){ip[i].st = 0;ip[i].owner = "";ip[i].t = 0;}}
}void change(int tc)
{/*在到达该过期时刻时,若该地址的状态是待分配,则该地址的状态会自动变为未分配,且占用者清空,过期时刻清零;否则该地址的状态会由占用自动变为过期,且过期时刻清零。*/for(int i = 1;i <= n;i ++)if(ip[i].t && ip[i].t <= tc){if (ip[i].st == 1){ip[i].st = 0;ip[i].owner = "";ip[i].t = 0;}else{ip[i].st = 3;ip[i].t = 0;}}
}int main()
{cin >> n >> tdef >> tmax >> tmin >> h;int q;cin >> q;while(q --){// <发送主机> <接收主机> <报文类型> <IP 地址> <过期时刻>string send , get , type;int x , tc , te;cin >> tc >> send >> get >> type >> x >> te;if(get != h && get != "*") {// 判断接收主机是否为本机,或者为 *,若不是,则判断类型是否为 Request,若不是,则不处理;if(type != "REQ") continue; }// 若类型不是 Discover、Request 之一,则不处理if(type != "REQ" && type != "DIS") continue;// 若接收主机为 *,但类型不是 Discover,或接收主机是本机,但类型是 Discover,则不处理。if(get == "*" && type != "DIS" || get == h && type == "DIS") continue;change(tc);// discover 报文if(type == "DIS"){int k = get_ip_d(send);if(!k) k = get_ip(0);if(!k) k = get_ip(3);if(!k) continue;// 将该 IP 地址状态设置为待分配,占用者设置为发送主机ip[k].st = 1 , ip[k].owner = send;// 若报文中过期时刻为 0 ,则设置过期时刻为 t+tdefif(!te) ip[k].t = tc + tdef;else{int w = te - tc;w = min(w , tmax) , w = max(w , tmin);ip[k].t = w + tc;}cout << h << " " << send << " OFR " << k << " " << ip[k].t << endl;}else{if(get != h) {update(send);continue;}if(!(x <= n && x >= 1 && ip[x].owner == send)){cout << h << " " << send << " NAK " << x << " " << 0 << endl;continue;}// 无论该 IP 地址的状态为何,将该 IP 地址的状态设置为占用ip[x].st = 2;if (!te) ip[x].t = tc + tdef;else{int w = te - tc;w = max(w , tmin), w = min(w, tmax);ip[x].t = tc + w;}cout << h << " " << send << " ACK " << x << " " << ip[x].t << endl;}}return 0;
}
第四题:校门外的树
解题思路:
dp问题
设 f[i] 为用了前 i 个障碍点的所有方案
f[i]=(f[0]∗cnt1+f[1]∗cnt2+…+f[j]∗cnt3+…+f[i−1]∗cnt(i−1))
f[i] 在循环的时候已经计算出结果,计算cnt值为重中之重
cnt值,也就是两个位置之间可以整除的结果个数,也就是约数个数。
#include<iostream>
#include<cstring>
#include<unordered_map>
#include<vector>using namespace std;const int N = 1010 , M = 1e5 + 10 , mod = 1e9 + 7;
int n;
int a[N] , f[N];
unordered_map<int , vector<int>>mp;
bool st[M];int main()
{for(int i = 1;i < M;i ++)for(int j = i * 2;j < M;j += i)mp[j].push_back(i); // 枚举因数cin >> n;for(int i = 0;i < n;i ++) cin >> a[i];f[0] = 1;for(int i = 1;i < n;i ++){memset(st , 0 , sizeof st);for(int j = i - 1;j >= 0;j --){int d = a[i] - a[j] , cnt = 0;for(int k : mp[d])if(!st[k]){cnt ++;st[k] = true;}st[d] = true;f[i] = (f[i] + (long long)f[j] * cnt) % mod;}}cout << f[n - 1] << endl;return 0;
}
第五题:疫苗运输
迪杰斯特拉+扩展欧几里得算法
(不会)
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>#define x first
#define y secondusing namespace std;typedef long long LL;
typedef pair<int, int> PII;const int N = 510;
const LL INF = 0x3f3f3f3f3f3f3f3fll;int n, m;
int len[N];
struct Node
{int cid, sum, pid;
};
vector<Node> ps[N];
vector<PII> line[N]; // x表示节点编号;y表示到下一个点的距离
LL dist[N], ans[N];
int pid[N];
bool st[N];LL exgcd(LL a, LL b, LL &x, LL &y) // 扩展欧几里得算法, 求x, y,使得ax + by = gcd(a, b)
{if (!b){x = 1; y = 0;return a;}LL d = exgcd(b, a % b, y, x);y -= (a / b) * x;return d;
}void dijkstra()
{memset(dist, 0x3f, sizeof dist);for (int i = 0; i < m; i ++ ){int d = 0;for (int j = 0; j < line[i].size(); j ++ ){if (line[i][j].x == 1){dist[i] = d;pid[i] = j;break;}d += line[i][j].y;}}for (int i = 0; i < m; i ++ ){int t = -1;for (int j = 0; j < m; j ++ )if (!st[j] && (t == -1 || dist[j] < dist[t]))t = j;st[t] = true;auto& l = line[t];auto d = dist[t];for (int j = pid[t], k = 0; k < l.size(); j = (j + 1) % l.size(), k ++ ){for (auto& c: ps[l[j].x]){if (st[c.cid]) continue; // 优化很重要LL a = d, b = len[t];LL x = c.sum, y = len[c.cid];LL X, Y;LL D = exgcd(b, y, X, Y);if ((x - a) % D) continue;X = (x - a) / D * X;y /= D;X = (X % y + y) % y;if (dist[c.cid] > a + b * X){dist[c.cid] = a + b * X;pid[c.cid] = c.pid;}}d += l[j].y;}}
}int main()
{scanf("%d%d", &n, &m);for (int i = 0; i < m; i ++ ){int cnt, sum = 0;scanf("%d", &cnt);for (int j = 0; j < cnt; j ++ ){int ver, t;scanf("%d%d", &ver, &t);ps[ver].push_back({i, sum, j});line[i].push_back({ver, t});sum += t;}len[i] = sum;}dijkstra();memset(ans, 0x3f, sizeof ans);for (int i = 0; i < m; i ++ ){if (dist[i] == INF) continue;LL d = dist[i];for (int j = pid[i], k = 0; k < line[i].size(); j = (j + 1) % line[i].size(), k ++ ){int ver = line[i][j].x;ans[ver] = min(ans[ver], d);d += line[i][j].y;}}for (int i = 2; i <= n; i ++ )if (ans[i] == INF) puts("inf");else printf("%lld\n", ans[i]);return 0;
}
相关文章:
第22次CCF计算机软件能力认证
第一题:灰度直方图 解题思路: 哈希表即可 #include<iostream> #include<cstring>using namespace std;const int N 610; int a[N]; int n , m , l;int main() {memset(a , 0 , sizeof a);cin >> n >> m >> l;for(int …...
Go语言基础之基本数据类型
Go语言中有丰富的数据类型,除了基本的整型、浮点型、布尔型、字符串外,还有数组、切片、结构体、函数、map、通道(channel)等。Go 语言的基本类型和其他语言大同小异。 基本数据类型 整型 整型分为以下两个大类: 按…...
Linux Tracing Technologies
目录 1. Linux Tracing Technologies 1. Linux Tracing Technologies Linux Tracing TechnologieseBPFXDPDPDK...
iOS自定义下拉刷新控件
自定义下拉刷新控件 概述 用了很多的别人的下拉刷新控件,想写一个玩玩,自定义一个在使用的时候也会比较有意思。使应用更加的灵动一些,毕竟谁不喜欢各种动画恰到好处的应用呢。 使用方式如下: tableview.refreshControl XRef…...
Springboot写单元测试
导入依赖 <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><exclusions><exclusion><groupId>org.junit.vintage</groupId><artifactId>junit-vintag…...
一篇文章教你使用Docker本地化部署Chatgpt(非api,速度非常快!!!)及裸连GPT的方式(告别镜像GPT)
本地搭建ChatGPT(非api调用) 第一种方法:使用Docker本地化部署第一步,下载安装Docker登录GPT 第二种方法:不部署项目,直接连接 第一种方法:使用Docker本地化部署 这种方法的好处就是没有登录限…...
前馈神经网络dropout实例
直接看代码。 (一)手动实现 import torch import torch.nn as nn import numpy as np import torchvision import torchvision.transforms as transforms import matplotlib.pyplot as plt#下载MNIST手写数据集 mnist_train torchvision.datasets.MN…...
Android DataStore:安全存储和轻松管理数据
关于作者:CSDN内容合伙人、技术专家, 从零开始做日活千万级APP。 专注于分享各领域原创系列文章 ,擅长java后端、移动开发、人工智能等,希望大家多多支持。 目录 一、导读二、概览三、使用3.1 Preferences DataStore添加依赖数据读…...
opencv进阶12-EigenFaces 人脸识别
EigenFaces 通常也被称为 特征脸,它使用主成分分析(Principal Component Analysis,PCA) 方法将高维的人脸数据处理为低维数据后(降维),再进行数据分析和处理,获取识别结果。 基本原理…...
The internal rate of return (IRR)
内部收益率 NPV(Net Present Value)_spencer_tseng的博客-CSDN博客...
半导体自动化专用静电消除器主要由哪些部分组成
半导体自动化专用静电消除器是一种用于消除半导体生产过程中的静电问题的设备。由于半导体制造过程中对静电的敏感性,静电可能会对半导体器件的质量和可靠性产生很大的影响,甚至造成元件损坏。因此,半导体生产中采用专用的静电消除器是非常重…...
【C++入门到精通】C++入门 —— deque(STL)
阅读导航 前言一、deque简介1. 概念2. 特点 二、deque使用1. 基本操作(增、删、查、改)2. 底层结构 三、deque的缺陷四、 为什么选择deque作为stack和queue的底层默认容器总结温馨提示 前言 文章绑定了VS平台下std::deque的源码,大家可以下载…...
Codeforces Round 893 (Div. 2) D.Trees and Segments
原题链接:Problem - D - Codeforces 题面: 大概意思就是让你在翻转01串不超过k次的情况下,使得a*(0的最大连续长度)(1的最大连续长度)最大(1<a<n)。输出n个数&…...
SpringBoot + Vue 前后端分离项目 微人事(九)
职位管理后端接口设计 在controller包里面新建system包,再在system包里面新建basic包,再在basic包里面创建PositionController类,在定义PositionController类的接口的时候,一定要与数据库的menu中的url地址到一致,不然…...
【业务功能篇71】Cglib的BeanCopier进行Bean对象拷贝
选择Cglib的BeanCopier进行Bean拷贝的理由是, 其性能要比Spring的BeanUtils,Apache的BeanUtils和PropertyUtils要好很多, 尤其是数据量比较大的情况下。 BeanCopier的主要作用是将数据库层面的Entity转化成service层的POJO。BeanCopier其实已…...
让eslint的错误信息显示在项目界面上
1.需求描述 效果如下 让eslint中的错误,显示在项目界面上 2.问题解决 1.安装 vite-plugin-eslint 插件 npm install vite-plugin-eslint --save-dev2.配置插件 // vite.config.js import { defineConfig } from vite import vue from vitejs/plugin-vue import e…...
手摸手带你实现一个开箱即用的Node邮件推送服务
目录 编辑 前言 准备工作 邮箱配置 代码实现 服务部署 使用效果 题外话 写在最后 相关代码: 前言 由于邮箱账号和手机号的唯一性,通常实现验证码的校验时比较常用的两种方式是手机短信推送和邮箱推送,此外,邮件推送服…...
【Linux网络】网络编程套接字 -- 基于socket实现一个简单UDP网络程序
认识端口号网络字节序处理字节序函数 htonl、htons、ntohl、ntohs socketsocket编程接口sockaddr结构结尾实现UDP程序的socket接口使用解析socket处理 IP 地址的函数初始化sockaddr_inbindrecvfromsendto 实现一个简单的UDP网络程序封装服务器相关代码封装客户端相关代码实验结…...
Python学习笔记第六十四天(Matplotlib 网格线)
Python学习笔记第六十四天 Matplotlib 网格线普通网格线样式网格线 后记 Matplotlib 网格线 我们可以使用 pyplot 中的 grid() 方法来设置图表中的网格线。 grid() 方法语法格式如下: matplotlib.pyplot.grid(bNone, whichmajor, axisboth, )参数说明:…...
机器学习与模式识别3(线性回归与逻辑回归)
一、线性回归与逻辑回归简介 线性回归主要功能是拟合数据,常用平方误差函数。 逻辑回归主要功能是区分数据,找到决策边界,常用交叉熵。 二、线性回归与逻辑回归的实现 1.线性回归 利用回归方程对一个或多个特征值和目标值之间的关系进行建模…...
树莓派超全系列教程文档--(61)树莓派摄像头高级使用方法
树莓派摄像头高级使用方法 配置通过调谐文件来调整相机行为 使用多个摄像头安装 libcam 和 rpicam-apps依赖关系开发包 文章来源: http://raspberry.dns8844.cn/documentation 原文网址 配置 大多数用例自动工作,无需更改相机配置。但是,一…...
三维GIS开发cesium智慧地铁教程(5)Cesium相机控制
一、环境搭建 <script src"../cesium1.99/Build/Cesium/Cesium.js"></script> <link rel"stylesheet" href"../cesium1.99/Build/Cesium/Widgets/widgets.css"> 关键配置点: 路径验证:确保相对路径.…...
.Net框架,除了EF还有很多很多......
文章目录 1. 引言2. Dapper2.1 概述与设计原理2.2 核心功能与代码示例基本查询多映射查询存储过程调用 2.3 性能优化原理2.4 适用场景 3. NHibernate3.1 概述与架构设计3.2 映射配置示例Fluent映射XML映射 3.3 查询示例HQL查询Criteria APILINQ提供程序 3.4 高级特性3.5 适用场…...
YSYX学习记录(八)
C语言,练习0: 先创建一个文件夹,我用的是物理机: 安装build-essential 练习1: 我注释掉了 #include <stdio.h> 出现下面错误 在你的文本编辑器中打开ex1文件,随机修改或删除一部分,之后…...
【android bluetooth 框架分析 04】【bt-framework 层详解 1】【BluetoothProperties介绍】
1. BluetoothProperties介绍 libsysprop/srcs/android/sysprop/BluetoothProperties.sysprop BluetoothProperties.sysprop 是 Android AOSP 中的一种 系统属性定义文件(System Property Definition File),用于声明和管理 Bluetooth 模块相…...
CMake 从 GitHub 下载第三方库并使用
有时我们希望直接使用 GitHub 上的开源库,而不想手动下载、编译和安装。 可以利用 CMake 提供的 FetchContent 模块来实现自动下载、构建和链接第三方库。 FetchContent 命令官方文档✅ 示例代码 我们将以 fmt 这个流行的格式化库为例,演示如何: 使用 FetchContent 从 GitH…...
C# 求圆面积的程序(Program to find area of a circle)
给定半径r,求圆的面积。圆的面积应精确到小数点后5位。 例子: 输入:r 5 输出:78.53982 解释:由于面积 PI * r * r 3.14159265358979323846 * 5 * 5 78.53982,因为我们只保留小数点后 5 位数字。 输…...
技术栈RabbitMq的介绍和使用
目录 1. 什么是消息队列?2. 消息队列的优点3. RabbitMQ 消息队列概述4. RabbitMQ 安装5. Exchange 四种类型5.1 direct 精准匹配5.2 fanout 广播5.3 topic 正则匹配 6. RabbitMQ 队列模式6.1 简单队列模式6.2 工作队列模式6.3 发布/订阅模式6.4 路由模式6.5 主题模式…...
人工智能(大型语言模型 LLMs)对不同学科的影响以及由此产生的新学习方式
今天是关于AI如何在教学中增强学生的学习体验,我把重要信息标红了。人文学科的价值被低估了 ⬇️ 转型与必要性 人工智能正在深刻地改变教育,这并非炒作,而是已经发生的巨大变革。教育机构和教育者不能忽视它,试图简单地禁止学生使…...
MySQL 知识小结(一)
一、my.cnf配置详解 我们知道安装MySQL有两种方式来安装咱们的MySQL数据库,分别是二进制安装编译数据库或者使用三方yum来进行安装,第三方yum的安装相对于二进制压缩包的安装更快捷,但是文件存放起来数据比较冗余,用二进制能够更好管理咱们M…...
