首页 > 试题广场 >

俄罗斯方块

[编程题]俄罗斯方块
  • 热度指数:29585 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 256M,其他语言512M
  • 算法知识视频讲解
小易有一个古老的游戏机,上面有着经典的游戏俄罗斯方块。因为它比较古老,所以规则和一般的俄罗斯方块不同。
荧幕上一共有 n 列,每次都会有一个 1 x 1 的方块随机落下,在同一列中,后落下的方块会叠在先前的方块之上,当一整行方块都被占满时,这一行会被消去,并得到1分。
有一天,小易又开了一局游戏,当玩到第 m 个方块落下时他觉得太无聊就关掉了,小易希望你告诉他这局游戏他获得的分数。

输入描述:
第一行两个数 n, m
第二行 m 个数,c1, c2, ... , cm , ci 表示第 i 个方块落在第几列
其中 1 <= n, m <= 1000, 1 <= ci <= n


输出描述:
小易这局游戏获得的分数
示例1

输入

3 9
1 1 2 2 2 3 1 2 3

输出

2
n,m = list(map(int, input().split()))
c = list(map(int, input().split()))
data=[]
for i in range(1,n+1):
    data.append(c.count(i))
print(min(data))

发表于 2020-05-01 09:18:15 回复(0)
import sys
a=sys.stdin.readlines()
lines=[line.strip().split() for line in a if line.strip()]
n,m=int(lines[0][0]),int(lines[0][1])
s=list(map(int,lines[1]))
res=s.count(1)
for i in range(2,n+1):
if s.count(i)<res:
res=s.count(i)
print(res)
编辑于 2020-03-28 10:02:37 回复(0)
from collections import Counter

n, m = map(int, input().strip().split())
game = list(map(int, input().strip().split()))
point = Counter(game)

if len(point) == n:
    print(min(point.values()))
else:
    print(0)
发表于 2020-03-22 11:59:33 回复(0)
n, m = map(int, input().split())
c=list(map(int,input().split()))
ans=[0 for i in range(n)]
for item in c:
    ans[item-1]+=1
print(min(ans))
发表于 2020-03-20 16:37:30 回复(0)
n,m=map(int,input().split())
L=map(int,input().split())
t=[0]*(n+1)
for i in L:
    t[i]+=1
print(min(t[1:]))
发表于 2020-03-10 23:59:16 回复(1)
import sys
lines=sys.stdin.readlines()
n,m=map(int,lines[0].strip().split())
b=list(map(int,lines[1].strip().split()))

task=[]

for i in range(1,n+1):
    count=b.count(i)
    task.append(count)
print(sorted(task)[0])

编辑于 2020-02-07 17:33:30 回复(0)
#第一次分享,究极简单的思路了,创建每列计数列表,
#对合理取值范围内的数计数完毕之后取列表最小值即可
n,m=map(int,input().strip().split())
list=list(map(int,input().strip().split()))
res_list=[]
for i in range(1,n+1):
    res_list.append(0)
for i in list:
    if i <=n:
        res_list[i-1]+=1
print(min(res_list))


发表于 2019-12-25 12:35:04 回复(0)

Python

from collections import Counter

n, m = map(int, input().split()[:2])
c = list(map(int, input().split()[:m]))
res = Counter(c).most_common()
print(0 if len(res) < n else res[-1][1])
发表于 2019-10-31 18:04:14 回复(0)
统计出现次数最少的数字。
import sys
n,m = map(int, sys.stdin.readline().split())
v= list(map(int, sys.stdin.readline().split()))
count1 = [0]*n
for i in range(1,n+1):
    count1[i-1] = v.count(i)
print(min(count1))


发表于 2019-09-26 17:47:08 回复(0)
a,b=map(int,input().split())
line=list(map(int,input().strip().split()))
c=0 m=[] for i in range(1,a+1): l=line.count(i)
    m.append(l)
m.sort() print(m[0])

发表于 2019-08-25 21:12:14 回复(0)
while True:
    try:
        n, m = map(int, input().split())
        d = {}
        num_list = list(map(int, input().split()))
        for col_num in num_list:
            d[col_num] = d.setdefault(col_num, 0) + 1
        if len(d) < n:
            print(0)
        else:
            min = d[1]
            for value in d.values():
                if value < min:
                    min = value
            print(min)
    except:
        break
发表于 2019-08-23 22:17:39 回复(0)
import sys
n,m=list(map(int,sys.stdin.readline().split()))
arr=list(map(int,sys.stdin.readline().split()))
if len(set(arr))<n:
    print(0)
else:
    num=[]
    for i in arr:
        num.append(arr.count(i))
    print(min(num))

发表于 2019-08-13 15:53:58 回复(0)
NM = raw_input().split()
L = raw_input().split()
N = int(NM[0])
M = int(NM[1])
Dict = {}
for i in range(N):
    Dict[i+1] = 0
for j in L:
    Dict[int(j)] = Dict[int(j)] + 1
print min(Dict.values())
发表于 2019-08-10 17:15:12 回复(0)
"""
统计每一列方块个数,最小值即为最终得分(包括0)
"""
from collections import Counter
import sys

if __name__ == "__main__":
    # sys.stdin = open('input.txt', 'r')
    n, m = list(map(int, input().strip().split()))
    c = list(map(int, input().strip().split()))
    v = Counter(c).values()
    ans = 0
    if len(v) == n:
        ans = min(v)
    print(ans)

编辑于 2019-07-03 11:37:21 回复(0)
n, m = map(int, raw_input().split(' '))
fall = map(int, raw_input().split(' '))
List = [0]*n 
for i in fall:
    List[i-1] += 1
print min(List)
发表于 2018-09-08 11:06:56 回复(0)
利用count和sort列表操作函数 n = int(input("input n:"))
m = int(input("input m:"))
c = []
while m > 0 :
    c.append(int(input("input c[]:")))
    m-=1
a = range(n)
d = []
for i in a :
    d.append(c.count(a[i]+1))
d.sort()
print(d[0])

发表于 2018-09-02 20:31:04 回复(0)