第十一届蓝桥杯大赛软件类省赛第二场C/C++大学B组(python解答)

Posted F=k·Δx

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了第十一届蓝桥杯大赛软件类省赛第二场C/C++大学B组(python解答)相关的知识,希望对你有一定的参考价值。

res = 0
for i in range(1, 2021):
    res += str(i).count('2')
print(res)


答案:624


辗转相除法

def func(a,b):
	x = a % b
	while (x != 0):
		a = b
		b = x
		x = a % b
	return b

num=0    
for i in range(1,2021):
    for j in range(1,2021):
        if func(i,j)==1:
            num+=1
print(num)

答案:2481215

小学奥数
对角线上的数分别是1,5,13,25
即可找到规律:

第n行第n列为:(n-1)^2 +n^2
print((20 - 1)**2 + 20**2)

答案:761

datetime真省事

import datetime
start = datetime.date(2000, 1, 1)
end = datetime.date(2020, 10, 2)
res = 0
while start != end:
    if start.day == 1 or start.weekday() == 0 :
        res += 2
    else:
        res += 1
    start += datetime.timedelta(days=1)
print(res)

答案:8879

你们的噩梦并查集回来了

from itertools import combinations
# 并查集模板
class UnionFind:
    def __init__(self, size: int):
        self.count = size
        self._father = 
        for i in range(size):
            self._father[i] = i

        self.weight = [1] * size

    def add(self, x):
        if x not in self._father:
            self._father[x] = x

    def find(self, x):
        root = x
        while self._father[root] != root:
            root = self._father[root]

        # 路径压缩
        while x != root:
            origin_root = self._father[x]
            self._father[x] = root
            x = origin_root

        return root

    def merge(self, x: int, y: int):
        root_x = self.find(x)
        root_y = self.find(y)
        if root_x != root_y:

            if self.weight[root_x] < self.weight[root_y]:
                root_x, root_y = root_y, root_x

            self._father[root_y] = root_x
            self.weight[root_x] += self.weight[root_y]
            self.count -= 1
        if root_x == root_y:
            return False

    def is_connected(self, x, y):
        return self.find(x) == self.find(y)


res = 0
list1 = [0, 1, 2, 3, 4, 5, 6]
a = len(list1)
for i in range(1, a+1):
    for item in (combinations(list1, i)):
        n = len(item)
        uf = UnionFind(n)
        for j in range(n):
            for k in range(j+1,n):
                if abs(item[j] - item[k]) == 1 or (item[j] == 0 and item[k] == 5) or (item[j] == 1 and item[k] == 6) or (item[j] == 2 and item[k] == 6) or (item[j] == 4 and item[k] == 6):
                    uf.merge(j, k)
        if uf.count == 1:
            res += 1
print(res)

答案:80

n = int(input())
passing = 0
excellence = 0
for i in range(n):
    score = int(input())
    if score >= 60:
        passing += 1
    if score >= 85:
        excellence += 1
pass_rate = passing/n*100
excellence_rate = excellence/n*100
print(str(round(pass_rate))+'%')
print(str(round(excellence_rate))+'%')

import datetime

n = str(input())
m = str(99991231)
def huiWenRi(start, end):

    s = datetime.datetime.strptime(start, '%Y%m%d')
    e = datetime.datetime.strptime(end, '%Y%m%d')
    while s <= e:  # 枚举日期
        string = s.strftime("%Y%m%d")
        if string == string[::-1]:
            print(string)
            break
        s += datetime.timedelta(1) 


def ababbaba(start, end):

    s = datetime.datetime.strptime(start, '%Y%m%d')
    e = datetime.datetime.strptime(end, '%Y%m%d')
    while s <= e:  # 枚举日期
        string = s.strftime("%Y%m%d")
        if string[0:2] == string[2:4] == string[5:3:-1] == string[7:5:-1]:
            print(string)
            break
        s += datetime.timedelta(1)
huiWenRi(n,m)
ababbaba(n,m)

list1=list(input())
list2=[-1 for i in range(26)]
count=0

for i in range(len(list1)):
    index=ord(list1[i])-ord('a')
    count+=(len(list1)-i)*(i-list2[index])
    list2[index]=i

print(count)

n1=eval(input())
ls=[tuple(map(int,input().split(" "))) for i in range(n1)]
se=set(ls)
ls=list(se)
del se
result=0
if ls:
    result=2
    for i in range(1,len(ls)):
        a1,b1=ls[i]
        se=set()
        for j in range(i):
            a2,b2=ls[j]
            if a1==a2:
                pass
            else:
                x=(b1-b2)/(a1-a2)
                y=a1*x+b1
                se.add((x,y))
        result+=len(se)+1
print(result)

以上是关于第十一届蓝桥杯大赛软件类省赛第二场C/C++大学B组(python解答)的主要内容,如果未能解决你的问题,请参考以下文章

2022 第十三届蓝桥杯大赛软件赛省赛(第二场),C/C++ 大学B组题解

2020 第十一届蓝桥杯大赛软件赛省赛(第二场),C/C++大学B组题解

2021 第十二届蓝桥杯大赛软件赛省赛(第二场),C/C++大学B组题解

2021 第十二届蓝桥杯大赛软件赛省赛(第二场),C/C++大学B组题解

第十二届蓝桥杯大赛软件赛省赛第二场C++B组

第十二届蓝桥杯大赛软件赛省赛第二场题解