蓝桥杯刷题--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)

相关推荐
财经资讯数据_灵砚智能5 分钟前
基于全球经济类多源新闻的NLP情感分析与数据可视化(日间)2026年6月7日
人工智能·python·ai·信息可视化·自然语言处理·ai编程·灵砚智能
星马梦缘5 分钟前
算法设计与分析 作业三 答案与解析
算法·线性规划·二分图匹配·多元最短路·流网络·bellmanford·匈牙利树算法
微风欲寻竹影8 分钟前
Java数据结构——二叉树(Binary Tree)详解
java·数据结构·算法
想吃火锅10058 分钟前
【leetcode】3.无重复字符的最长字串js版
算法·leetcode·职场和发展
smith成长之旅12 分钟前
08 | Mem0 框架分析: BM25 的 Sigmoid 归一化
数据库·python·算法
DogDaoDao12 分钟前
【第 04 篇】列表与元组 —— 序列类型核心详解
人工智能·python·深度学习·神经网络·机器学习·conda·numpy
dongf201913 分钟前
R 语言随机森林算法
算法·随机森林·r语言
idingzhi13 分钟前
A股量化策略日报(2026年06月07日)
python
xingpanvip21 分钟前
使用 Webwright 在 CSDN 自动发文:Python 浏览器自动化实践
开发语言·python·自动化
armwind23 分钟前
openISP学习7-CCM — Color Correction Matrix(色彩校正矩阵)
python·学习·矩阵