蓝桥杯刷题--python-23

2.危险系数 - 蓝桥云课 (lanqiao.cn)

复制代码
n, m = map(int, input().split())
map_ = [[] for i in range(n + 1)]
used = [0 for i in range(n + 1)]
used_ = [0 for i in range(n + 1)]
cnt = 0
res = []
for _ in range(m):
    u, v = map(int, input().split())
    map_[u].append(v)
    map_[v].append(u)

u, v = map(int, input().split())


def dfs(u, v):
    global cnt
    if u == v:
        cnt += 1
        for i in res:
            used_[i] += 1

        return
    for i in map_[u]:
        if not used[i]:
            used[i] = 1
            res.append(i)
            dfs(i, v)
            res.pop()
            used[i] = 0


dfs(u, v)
ans = 0
for i in range(1, n + 1):
    if used_[i] == cnt and i != u and i != v:
        ans += 1
print(ans)

3.串变换 - 蓝桥云课 (lanqiao.cn)

复制代码
def op(z, x, y_v, arr):
    if z == 1:
        arr[x] = (int(arr[x]) + y_v) % 10
    else:

        arr[x], arr[y_v] = arr[y_v], arr[x]


# 输入
n = int(input())
s = list(input())
t = list(input())
k = int(input())
k_ = []
used = [0 for _ in range(k)]
for _ in range(k):
    a, b, c = map(int, input().split())
    k_.append((a, b, c))

# print(k_)
j = False


def dfs(index, s):
    global j

    if index == k:
        return

    for i in range(k):
        if not used[i]:
            tmp = s
            used[i] = 1
            op(k_[i][0], k_[i][1], k_[i][2], s)
            if not j:
                l = 0
                for x in range(n):

                    if int(s[x]) != int(t[x]):
                        l = 1

                        break
                if not l:
                    j = True
            else:
                return

            dfs(index + 1, s)
            s = tmp

            used[i] = 0


dfs(0, s)
if j:
    print("Yes")
else:
    print("No")

8.仙境诅咒 - 蓝桥云课 (lanqiao.cn)

import os

import sys

请在此输入您的代码

n = int(input())

man = \[\]

for _ in range(n):

x, y = map(int, input().split())

man.append(x, y)

D = int(input())

man_used = 0 for _ in range(n)

def dfs(index):

man_usedindex = 1

for i in range(n):

if not man_usedi:

r_ = (mani0 - manindex0) ** 2 + (mani1 - manindex1) ** 2

if r_ <= D * D:

dfs(i)

dfs(0)

for i in man_used:

if i:

print(1)

else:print(0)

相关推荐
yongche_shi2 分钟前
ragas官方文档中文版(五十)
开发语言·python·ai·ragas·如何评估和改进 rag 应用
QiLinkOS14 分钟前
第三视觉理解徐玉生与他的商业活动(30)
大数据·c++·人工智能·算法·开源协议
疯狂打码的少年31 分钟前
【操作系统】页面置换算法(OPT/FIFO/LRU)
算法
小O的算法实验室1 小时前
2026年CIE,优化客货协同运输:综合地铁系统的列车容量动态分配
算法
AI行业学习1 小时前
Notepad++ 官方下载 + 完整安装 + 全套优化配置(2026最新)
开发语言·人工智能·python·前端框架·html·notepad++
Coder_Shenshen2 小时前
西门子S7CommPlus协议鉴权算法原理与流程详解
网络·后端·算法
大圣编程2 小时前
Python中continue语句的用法是什么?
开发语言·前端·python
硕风和炜2 小时前
【LeetCode: 2492. 两个城市间路径的最小分数 + DFS】
java·算法·leetcode·深度优先·dfs·bfs·并查集
云烟成雨TD2 小时前
LangFlow 1.x 系列【5】可视化编辑页面功能说明
人工智能·python·agent
我是一颗柠檬3 小时前
【Java项目技术亮点】加权轮询负载均衡算法
java·算法·负载均衡