Blue Bridge Cup Day 3 (Python)

It is known that the sizes of the three rectangles are a b 1 , a b 2 and a b 3 in turn. Among all the polygons that can be assembled with these 3 rectangles, what is the minimum number of sides?
import os
import sys

# 请在此输入您的代码
# 三种情况 4 6 8
# 组合方式3种 ,每个两种摆放方式 2*2*2=8
n = int(input())
m = []
for  i in  range(n):
  m.append(list(map(int,input().split())))

def cheak(z):
    ans = 8
    for i in range(0,2): # 第一个长方形长
      for j in range(2,4): # 第二个长方形长
        for k in range(4,6): # 第三个长方形长
          if z[i]==z[j]==z[k] and z[0]+z[1]-z[i] == z[2]+z[3]-z[j] == z[4]+z[5]-z[k]:
            #return 4
            ans=min(4,ans)
          elif z[i]+z[j]==z[i]+z[k] and z[0]+z[1]-z[i] == z[2]+z[3]-z[j] + z[4]+z[5]-z[k]:
            #return 4
            ans=min(4,ans)
          elif z[i]==z[j]+z[k] and  z[2]+z[3]-z[j] != z[4]+z[5]-z[k]:
            #return 6
            ans=min(6,ans)
          elif z[i]!=z[j]+z[k] and  z[2]+z[3]-z[j] != z[4]+z[5]-z[k]:
            #return 8
            pass # 不写会报错
    return ans
for z in m:
  print(cheak(z))

import os
import sys

# 请在此输入您的代码
n = int(input())
m=[]
for i in range(n):
  m.append(int(input()))
# print(max(m))
# print(min(m))
# m.remove(max(m))
# m.remove(min(m))
m.sort()
#m.remove(m[0])
#m.remove(m[-1])
print('{:.2f}'.format(sum(m)/len(m)))

Xiaolan has a black and white image consisting of n × m pixels, in which there are n rows from top to bottom , and each row has m columns from left to right. Each pixel is represented by a grayscale value between 0 and 255.
Now, Xiaolan is going to blur the image. The method of operation is:
for each pixel, sum all the pixels (may be 9 pixels or less than 9 pixels) in the 3×3 area centered on it Divide by the number of pixels in this range (round down), and the obtained value is the blurred result.
Note that each pixel is summed with the gray value in the original image.

n, m = map(int, input().split())

matrix = [[int(x) for x in input().split()] for _ in range(n)]


def pooling(x, y):
    s = 0
    cnt = 0

    for i in range(x - 1, x + 1 + 1):
        for j in range(y - 1, y + 1 + 1):

            if 0 <= i < n and 0 <= j < m:
                s += matrix[i][j]
                cnt += 1

    return s // cnt


# img = [[pooling(i, j) for j in range(m)] for i in range(n)]


img = []
for i in range(n):
    img.append([])
    for j in range(m):
        img[-1].append(pooling(i, j))
        

for l in img:
    print(*l)

import sys  #设置递归深度
import collections  #队列
import itertools  # 排列组合
import heapq  #小顶堆
import math
sys.setrecursionlimit(300000)
import functools   # 自定义比较函数  -1不变,1交换
import datetime   # date,timedelta,isoweekday()


import os
import sys
 
# 请在此输入您的代码
s = input()
 
count=0
# 00 01 .. 0(n-1)
#
# n-1(n-1)
for i in range(len(s)):
  for j in range(i,len(s)):
    mydict= {}
    for k in s[i:j+1]:
      mydict[k]=mydict.get(k,0)+1
    m=list(mydict.values())
    count+=m.count(1)
    
 
print(count)
 

Expand the array 4*4 to 5*5, fill it with 0
n,m,k = map( int,input( ).split( ))
a = [[0] for i in range( n)] #创建n行
a.insert(0,[0]*( m+1)) #最前面插入一行,m+1列
for i in range( 1,n+1):#从a[1][1]开始,读矩阵
    a[i].extend ( map(int,input( ).split( )))

1 2 3
4 5 6
7 8 9

0 0 0 0
0 1 2 3
0 4 5 6
0 7 8 9

a=[[0]*(m+1)]
for i in range(n):
    a.append([0]+list(map(int,input().split())))

n,m = map( int,input( ).split( ))
a = [0] + list( map( int,input().split()))
for i in range(m):
  w= list(map( int,input( ).split()))
  if len(w) ==3:  #区间询问:[L,R]的区间和
    q,L,R= w
    print( sum( a[L:R+1]))
  else:             #区间修改:把[L,R]的每个元素加上d
    q,L,R,d = w
    for i in range(L,R+1):
      a[i]+=d

#标准答案差分数组

Guess you like

Origin blog.csdn.net/weixin_52261094/article/details/129544602