蓝桥杯刷题--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_used[index] = 1

for i in range(n):

if not man_used[i]:

r_ = (man[i][0] - man[index][0]) ** 2 + (man[i][1] - man[index][1]) ** 2

if r_ <= D * D:

dfs(i)

dfs(0)

for i in man_used:

if i:

print(1)

else:print(0)

相关推荐
老胖闲聊1 小时前
Python Copilot【代码辅助工具】 简介
开发语言·python·copilot
Blossom.1181 小时前
使用Python和Scikit-Learn实现机器学习模型调优
开发语言·人工智能·python·深度学习·目标检测·机器学习·scikit-learn
曹勖之2 小时前
基于ROS2,撰写python脚本,根据给定的舵-桨动力学模型实现动力学更新
开发语言·python·机器人·ros2
lyaihao3 小时前
使用python实现奔跑的线条效果
python·绘图
int型码农3 小时前
数据结构第八章(一) 插入排序
c语言·数据结构·算法·排序算法·希尔排序
UFIT3 小时前
NoSQL之redis哨兵
java·前端·算法
喜欢吃燃面3 小时前
C++刷题:日期模拟(1)
c++·学习·算法
SHERlocked933 小时前
CPP 从 0 到 1 完成一个支持 future/promise 的 Windows 异步串口通信库
c++·算法·promise
ai大师3 小时前
(附代码及图示)Multi-Query 多查询策略详解
python·langchain·中转api·apikey·中转apikey·免费apikey·claude4
怀旧,3 小时前
【数据结构】6. 时间与空间复杂度
java·数据结构·算法