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

相关推荐
Awesome Baron4 分钟前
《Learning Langchain》阅读笔记8-RAG(4)在vector store中存储embbdings
python·jupyter·chatgpt·langchain·llm
阡之尘埃7 分钟前
Python数据分析案例73——基于多种异常值监测算法探查内幕交易信息
人工智能·python·机器学习·数据分析·异常检测·无监督学习
雾月5537 分钟前
LeetCode 1292 元素和小于等于阈值的正方形的最大边长
java·数据结构·算法·leetcode·职场和发展
蓝莓味柯基1 小时前
Python3:文件操作
python
xiaoh_71 小时前
解决视频处理中的 HEVC 解码错误:Could not find ref with POC xxx【已解决】
python·ffmpeg·音视频
YuforiaCode2 小时前
第十二届蓝桥杯 2021 C/C++组 直线
c语言·c++·蓝桥杯
明月与玄武2 小时前
Python编程的真谛:超越语法,理解编程本质
python·编程语言
CodeCraft Studio2 小时前
Excel处理控件Aspose.Cells教程:使用 Python 在 Excel 中进行数据验
开发语言·python·excel
知来者逆2 小时前
计算机视觉——速度与精度的完美结合的实时目标检测算法RF-DETR详解
图像处理·人工智能·深度学习·算法·目标检测·计算机视觉·rf-detr
阿让啊2 小时前
C语言中操作字节的某一位
c语言·开发语言·数据结构·单片机·算法