csp202009-2 风险人群筛查 python 满分

csp202009-2

"""
5 2 6 20 40 100 80
100 80 100 80 100 80 100 80 100 80 100 80
60 50 60 46 60 42 60 38 60 34 60 30
10 60 14 62 18 66 22 74 26 86 30 100
90 31 94 35 98 39 102 43 106 47 110 51
0 20 4 20 8 20 12 20 16 20 20 20
"""

"""
1 3 8 0 0 10 10
-1 -1 0 0 0 0 -1 -1 0 0 -1 -1 0 0 0 0
"""
import sys
def judgeInArea(xl,yd,xr,yu,x,y):
    if x>=xl and x <= xr and y>=yd and y<= yu:
        return '1'
    else:
        return '0'
def transferAddress(xl,yd,xr,yu,address):
    i=0
    result=[]
    while i<len(address)/2:
        result.append(judgeInArea(xl,yd,xr,yu,address[2*i],address[2*i+1]))
        i+=1
    return result
n,k,t,xl,yd,xr,yu=map(int,input().split())
# 连续k个,每人t时刻,n个人
data={}
i=1
while i<=n:
    address=list(map(int,sys.stdin.readline().strip('\n').split()))
    data[i]=transferAddress(xl,yd,xr,yu,address)
    # 第i个人的位置,记录
    i+=1
i=1
answer=[0,0]
while i<=n:
    if (''.join(data[i])).find('1'*k) != -1:
        answer[1]+=1
    if '1' in data[i]:
        answer[0]+=1
    i+=1
print(answer[0])
print(answer[1])


用到了列表转字符串,用字符串函数,快速查找,相当于找公共子串

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值