第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.线性回归 利用回归方程对一个或多个特征值和目标值之间的关系进行建模…...
【杂谈】-递归进化:人工智能的自我改进与监管挑战
递归进化:人工智能的自我改进与监管挑战 文章目录 递归进化:人工智能的自我改进与监管挑战1、自我改进型人工智能的崛起2、人工智能如何挑战人类监管?3、确保人工智能受控的策略4、人类在人工智能发展中的角色5、平衡自主性与控制力6、总结与…...
CMake基础:构建流程详解
目录 1.CMake构建过程的基本流程 2.CMake构建的具体步骤 2.1.创建构建目录 2.2.使用 CMake 生成构建文件 2.3.编译和构建 2.4.清理构建文件 2.5.重新配置和构建 3.跨平台构建示例 4.工具链与交叉编译 5.CMake构建后的项目结构解析 5.1.CMake构建后的目录结构 5.2.构…...
渗透实战PortSwigger靶场-XSS Lab 14:大多数标签和属性被阻止
<script>标签被拦截 我们需要把全部可用的 tag 和 event 进行暴力破解 XSS cheat sheet: https://portswigger.net/web-security/cross-site-scripting/cheat-sheet 通过爆破发现body可以用 再把全部 events 放进去爆破 这些 event 全部可用 <body onres…...
第25节 Node.js 断言测试
Node.js的assert模块主要用于编写程序的单元测试时使用,通过断言可以提早发现和排查出错误。 稳定性: 5 - 锁定 这个模块可用于应用的单元测试,通过 require(assert) 可以使用这个模块。 assert.fail(actual, expected, message, operator) 使用参数…...
基于Docker Compose部署Java微服务项目
一. 创建根项目 根项目(父项目)主要用于依赖管理 一些需要注意的点: 打包方式需要为 pom<modules>里需要注册子模块不要引入maven的打包插件,否则打包时会出问题 <?xml version"1.0" encoding"UTF-8…...
力扣-35.搜索插入位置
题目描述 给定一个排序数组和一个目标值,在数组中找到目标值,并返回其索引。如果目标值不存在于数组中,返回它将会被按顺序插入的位置。 请必须使用时间复杂度为 O(log n) 的算法。 class Solution {public int searchInsert(int[] nums, …...
【安全篇】金刚不坏之身:整合 Spring Security + JWT 实现无状态认证与授权
摘要 本文是《Spring Boot 实战派》系列的第四篇。我们将直面所有 Web 应用都无法回避的核心问题:安全。文章将详细阐述认证(Authentication) 与授权(Authorization的核心概念,对比传统 Session-Cookie 与现代 JWT(JS…...
es6+和css3新增的特性有哪些
一:ECMAScript 新特性(ES6) ES6 (2015) - 革命性更新 1,记住的方法,从一个方法里面用到了哪些技术 1,let /const块级作用域声明2,**默认参数**:函数参数可以设置默认值。3&#x…...
门静脉高压——表现
一、门静脉高压表现 00:01 1. 门静脉构成 00:13 组成结构:由肠系膜上静脉和脾静脉汇合构成,是肝脏血液供应的主要来源。淤血后果:门静脉淤血会同时导致脾静脉和肠系膜上静脉淤血,引发后续系列症状。 2. 脾大和脾功能亢进 00:46 …...
字符串哈希+KMP
P10468 兔子与兔子 #include<bits/stdc.h> using namespace std; typedef unsigned long long ull; const int N 1000010; ull a[N], pw[N]; int n; ull gethash(int l, int r){return a[r] - a[l - 1] * pw[r - l 1]; } signed main(){ios::sync_with_stdio(false), …...
