牛客每日练习----Beautiful Trees Cutting,Professional Manager,Operating System

本文精选了三道来自牛客网的算法竞赛题目,涵盖了字符串处理、并查集和页面置换算法,通过详细解析帮助读者深入理解算法设计与实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

我喜欢给自己压力,必须得定一个很高的目标,逼自己朝着这个目标前进,不管会不会实现,都是一个动力。                                      ----喻言

链接:https://ac.nowcoder.com/acm/problem/15695
来源:牛客网

题目描述

It’s universally acknowledged that there’re innumerable trees in the campus of HUST.

One day Xiao Ming is walking on a straight road and sees many trees line up in the right side. Heights of each tree which is denoted by a non-negative integer from 0 to 9 can form a tree string. It's very surprising to find that the tree string can be represent as an initial string repeating K times. Now he wants to remove some trees to make the rest of the tree string looks beautiful. A string is beautiful if and only if the integer it represents is divisible by five. Now he wonders how many ways there are that he could make it.

Note that when we transfer the string to a integer, we ignore the leading zeros. For example, the string “00055” will be seen as 55. And also pay attention that two ways are considered different if the removed trees are different. The result can be very large, so printing the answer (mod 1000000007) is enough. And additionally, Xiao Ming can't cut down all trees.

输入描述:

The first line contains a single integer K(1≤k≤109)(1 \leq k \leq 10^{9})(1≤k≤109), which indicates that the tree string is the initial string repeating K times.

The second line is the initial string S(1≤∣S∣≤105)(1 \leq |S| \leq 10^{5})(1≤∣S∣≤105).

输出描述:

A single integer, the number of ways to remove trees mod 1000000007.

示例1

输入

复制

1
100

输出

复制

6

说明

Initially, the sequence is ‘100’. There are
6 ways:
100
1_0
10_
_00
__0
_0_

示例2

输入

复制

3
125390

输出

复制

149796
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <ctime>
#include <cctype>
#include <bitset>
#include <utility>
#include <sstream>
#include <complex>
#include <iomanip>
#include<climits>//INT_MAX
#define pr pair<ll,int>
#define inf 0x3f3f3f3f
#define llinf 0x3f3f3f3f3f3f3f3fll
#define dinf 1000000000000.0
typedef long long ll;
using namespace std;
int const N=2000010;
int const mod=1e9+7;
const int maxn=1e5+10;
ll k;
char s[maxn];
ll ksm(ll a,ll b){
    ll r=1;
    while(b){
        if(b&1) 
			r=r*a%mod;
        a=a*a%mod;
		b>>=1;
    }
	return r;
}
int main(){
    cin>>k;
	scanf("%s",s);
    int d=strlen(s);
    ll q=ksm(2,d);
    ll p=((ksm(q,k)-1)*ksm(q-1,mod-2))%mod;
    ll jg=0;
    for(int i=0;i<d;++i)
        if(s[i]=='0'||s[i]=='5') 
			jg=(jg+ksm(2,i))%mod;
    jg=jg*p%mod;
    cout<<jg<<endl;
    return 0;
}

链接:https://ac.nowcoder.com/acm/problem/15696
来源:牛客网

题目描述

It’s universally acknowledged that there’re innumerable trees in the campus of HUST. 

Thus a professional tree manager is needed. Your task is to write a program to help manage the trees. 

Initially, there are n forests and for the i-th forest there is only the i-th tree in it. Given four kinds of operations.

1 u v, merge the forest containing the u-th tree and the forest containing the v-th tree;

2 u, separate the u-th tree from its forest;

3 u, query the size of the forest which contains the u-th tree;

4 u v, query whether the u-th tree and the v-th tree are in the same forest.

输入描述:

The first line contains an integer T(T≤10)(T \leq 10)(T≤10), indicating the number of testcases.

In each test case:

The first line contains two integers N and Q(1≤N,Q≤105)(1 \leq N,Q \leq 10^{5})(1≤N,Q≤105), indicating the number of initial forests and the number of operations.

Then Q lines follow, and each line describes an operation(1≤u,v≤N,u≠v)(1 \leq u,v \leq N,u\neq v)(1≤u,v≤N,u​=v).

输出描述:

For each test cases, the first line should be "Case #i:", where i indicate the test case i.
For each query 3, print a integer in a single line.
For each query 4, print "YES" or "NO" in a single line.

示例1

输入

复制

1
10 8
3 1
4 1 2
1 1 2
3 1
4 1 2
2 1
3 1
4 1 2

输出

复制

Case #1:
1
NO
2
YES
1
NO
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <ctime>
#include <cctype>
#include <bitset>
#include <utility>
#include <sstream>
#include <complex>
#include <iomanip>
#include<climits>//INT_MAX
#define pr pair<ll,int>
#define inf 0x3f3f3f3f
#define llinf 0x3f3f3f3f3f3f3f3fll
#define dinf 1000000000000.0
typedef long long ll;
using namespace std;
int const N=2000010;
int const mod=1e9+7;
const int maxn=1e5+10;
int n,m,k,p[300010];
int fd(int x) {
    if (p[x]<0) 
		return x;
    return p[x]=fd(p[x]);
}
void hb(int x, int y) {
    int rx=fd(x);    
	int ry=fd(y);
    if (rx==ry) 
		return;
    int t=p[rx]+p[ry];
    if (p[rx]<p[ry]) {
        p[rx]=t;
        p[ry]=rx;
    }
    else {
        p[ry]=t;
        p[rx]=ry;
    }
}
int main() {
    int q,ct=0;
    scanf("%d", &q);
    while(q--) {
        printf("Case #%d:\n", ++ct);
        scanf("%d%d", &n, &m);
        for (int i=1; i<=n; i++) 
            p[i]=i+n;
        for (int i=n+1; i<=300000; i++)
            p[i]=-1;
        k=1;
        while(m--){
            int t, x, y;
            scanf("%d%d", &t, &x);
            if (t==1){
                scanf("%d", &y);
                hb(x, y);
            }
            else if (t==2){
                int xx=fd(x);
                p[xx]++;
                p[x]=2*n+k;
                k++;
            }
            else if (t==3) {
                int xx=fd(x);
                int s=-p[xx];
                printf("%d\n", s);
            }
            else {
                scanf("%d", &y);
                int xx=fd(x);    
				int yy=fd(y);
                if (xx==yy) 
					printf("YES\n");
                else 
					printf("NO\n");
            }
        }
    }
    return 0;
}

链接:https://ac.nowcoder.com/acm/problem/15688
来源:牛客网

题目描述

在学习Operating System的过程中,Glory遇到了这样一个问题,现在有一个大小为可以容纳N个页面的内存,硬盘内的内容被分成M个页面,用1~M来标识,一开始内存里没有任何页面,接下来用户会请求Q个页面,你需要设计一个置换算法,使得缺页发生的次数最少。缺页是指用户请求某个编号的页面,但这个页面没有在内存中的情况。发生缺页之后,你必须要把硬盘内对应的页面调入内存中,如果内存已满,你需要置换掉当前内存中的某个页面。

输入描述:

多组数据,请处理到输入结束。
每组数据,第一行为三个整数N,M,Q (0 < N,M,Q <= 50000)
接下来一行Q个数,表示用户请求的页面编号。

输出描述:

对于每组数据,输出一个数,表示最少的缺页次数。

示例1

输入

复制

2 3 5
3 1 2 1 2
3 4 5 
3 2 1 4 3

输出

复制

3
4
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <ctime>
#include <cctype>
#include <bitset>
#include <utility>
#include <sstream>
#include <complex>
#include <iomanip>
#include<climits>//INT_MAX
#define PP pair<ll,int>
#define inf 0x3f3f3f3f
#define llinf 0x3f3f3f3f3f3f3f3fll
#define dinf 1000000000000.0
typedef long long ll;
using namespace std;
int const N=2000010;
int const mod=1e9+7;
const int maxn=1e5+10;
int a[50010],vis[50010],pos[50010],mov[50010];
int main()
{
    int n,q,m;
    while(~scanf("%d %d %d",&n,&m,&q)) {
    	int jg=0;
        priority_queue<PP>que;
        for(int i=1;i<=q;i++)
            scanf("%d",&a[i]);
        for(int i=0;i<=m;i++)
            pos[i]=50001;
        memset(vis,0,sizeof(vis));
        for(int i=q;i>=1;i--) {
                mov[i]=pos[a[i]];
                pos[a[i]]=i;
        }
        for(int i=1;i<=q;i++) {
            if(jg<n&&!vis[a[i]]) {
                jg++;
                vis[a[i]]=1;
            }
            else if(jg>=n&&!vis[a[i]]) {
                jg++;
                vis[a[i]]=1;
                vis[que.top().second]=0;
                que.pop();
            }
            que.push(make_pair(mov[i],a[i]));
        }
        printf("%d\n",jg);
    }
    return 0;
}

 

标题SpringBoot基于Web的图书借阅管理信息系统设计与实现AI更换标题第1章引言介绍图书借阅管理信息系统的研究背景、意义、现状以及论文的研究方法和创新点。1.1研究背景与意义分析当前图书借阅管理的需求和SpringBoot技术的应用背景。1.2国内外研究现状概述国内外在图书借阅管理信息系统方面的研究进展。1.3研究方法与创新点介绍本文采用的研究方法和系统设计的创新之处。第2章相关理论技术阐述SpringBoot框架、Web技术和数据库相关理论。2.1SpringBoot框架概述介绍SpringBoot框架的基本概念、特点和核心组件。2.2Web技术基础概述Web技术的发展历程、基本原理和关键技术。2.3数据库技术应用讨论数据库在图书借阅管理信息系统中的作用和选型依据。第3章系统需求分析对图书借阅管理信息系统的功能需求、非功能需求进行详细分析。3.1功能需求分析列举系统应具备的各项功能,如用户登录、图书查询、借阅管理等。3.2非功能需求分析阐述系统应满足的性能、安全性、易用性等方面的要求。第4章系统设计详细介绍图书借阅管理信息系统的设计方案和实现过程。4.1系统架构设计给出系统的整体架构,包括前后端分离、数据库设计等关键部分。4.2功能模块设计具体阐述各个功能模块的设计思路和实现方法,如用户管理模块、图书管理模块等。4.3数据库设计详细介绍数据库的设计过程,包括表结构、字段类型、索引等关键信息。第5章系统实现与测试对图书借阅管理信息系统进行编码实现,并进行详细的测试验证。5.1系统实现介绍系统的具体实现过程,包括关键代码片段、技术难点解决方法等。5.2系统测试给出系统的测试方案、测试用例和测试结果,验证系统的正确性和稳定性。第6章结论与展望总结本文的研究成果,指出存在的问题和未来的研究方向。6.1研究结论概括性地总结本文的研究内容和取得的成果。6.2展望对图书借阅管理
摘 要 基于SpringBoot的电影院售票系统为用户提供了便捷的在线购票体验,覆盖了从注册登录到观影后的评价反馈等各个环节。用户能够通过系统快速浏览和搜索电影信息,包括正在热映及即将上映的作品,并利用选座功能选择心仪的座位进行预订。系统支持多种支付方式如微信、支付宝以及银行卡支付,同时提供积分兑换和优惠券领取等功能,增强了用户的购票体验。个人中心允许用户管理订单、收藏喜爱的影片以及查看和使用优惠券,极大地提升了使用的便利性和互动性。服聊天功能则确保用户在遇到问题时可以即时获得帮助。 后台管理人员,系统同样提供了全面而细致的管理工具来维护日常运营。管理员可以通过后台首页直观地查看销售额统计图,了解票房情况并据此调整策略。电影信息管理模块支持新增、删除及修改电影资料,确保信息的准确与及时更新。用户管理功能使得管理员可以方便地处理用户账号,包括导入导出数据以供分析。订单管理模块简化了对不同状态订单的处理流程,提高了工作效率。优惠券管理和弹窗提醒管理功能有助于策划促销活动,吸引更多观众。通过这样的集成化平台,SpringBoot的电影院售票系统不仅优化了用户的购票体验,也加强了影院内部的管理能力,促进了业务的发展和服务质量的提升。 关键词:电影院售票系统;SpringBoot框架;Java技术
内容概要:本文介绍了2025年中国网络安全的十大创新方向,涵盖可信数据空间、AI赋能数据安全、ADR(应用检测与响应)、供应链安全、深度伪造检测、大模型安全评估、合规管理与安全运营深度融合、AI应用防火墙、安全运营智能体、安全威胁检测智能体等。每个创新方向不仅提供了推荐的落地方案和典型厂商,还详细阐述了其核心能力、应用场景、关键挑战及其用户价值。文中特别强调了AI技术在网络安全领域的广泛应用,如AI赋能数据安全、智能体驱动的安全运营等,旨在应对日益复杂的网络威胁,提升企业和政府机构的安全防护能力。 适合人群:从事网络安全、信息技术、数据管理等相关工作的专业人士,尤其是负责企业信息安全、技术架构设计、合规管理的中高层管理人员和技术人员。 使用场景及目标:①帮助企业理解和应对最新的网络安全威胁和技术趋势;②指导企业选择合适的网络安全产品和服务,提升整体安全防护水平;③协助企业构建和完善自身的网络安全管理体系,确保合规运营;④为技术研发人员提供参考,推动技术创新和发展。 其他说明:文章内容详尽,涉及多个技术领域和应用场景,建议读者根据自身需求重点关注相关章节,并结合实际情况进行深入研究和实践。文中提到的多个技术和解决方案已在实际应用中得到了验证,具有较高的参考价值。此外,随着技术的不断发展,文中提及的部分技术和方案可能会有所更新或改进,因此建议读者保持关注最新的行业动态和技术进展。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值