• CCF_2020_09 python


    第一题:

    题目背景

    2020 年 6 月 8 日,国务院联防联控机制发布《关于加快推进新冠病毒核酸检测的实施意见》,提出对“密切接触者”等八类重点人群“应检尽检”,其他人群“愿检尽检”。

    题目描述

    某市设有n个核酸检测点,编号从1到n,其中i号检测点的位置可以表示为一个平面整数坐标(xi,yi)。为方便预约核酸检测,请根据市民所在位置(X,Y),查询距其最近的三个检测点。 多个检测点距离相同时,编号较小的视为更近。

    输入格式

    从标准输入读入数据。

    输入共n+1行。

    第一行包含用空格分隔的三个整数n、X和Y,表示检测点总数和市民所在位置。

    第二行到第n+1行依次输入n个检测点的坐标。第i+1行(1 <= i <= n)包含用空格分隔的两个整数xi和yi表示i号检测点所在位置。

    输出格式

    输出到标准输出。

    输出共三行,按距离从近到远,依次输出距离该市民最近的三个检测点编号。

    样例1输入

    3 2 2
    2 2
    2 3
    2 4

    样例1输出

    1
    2
    3

    样例2输入

    5 0 1
    -1 0
    0 0
    1 0
    0 2
    -1 2
    

    样例2输出

    2
    4
    1

    样例2解释

    检测点编号 1 2 3 4 5
    距离 2 1 2 1 2

    子任务

    全部的测试点满足,3<= n <= 200,所有坐标均为整数且绝对值不超过1000.

    提示

    市民到第i号检测点的距离Di,可由如下公式算出:

     代码:

    def juedui(x):   
        if x>=0:
            return x
        else:
            return -x
    
    
    def func(x,y,X,Y):   
        sum = juedui(X-x)**2+juedui(Y-y)**2
        return sum
    
    def get_min(list):
        x = sorted(list)
        return [x[0], x[1], x[2]]
            
    
    n, X, Y = [int(i) for i in input().split()]
    location = []
    for i in range(n):
        sign = [int(i) for i in input().split()]
        location.append(sign)
    
    list = []
    for i in range(len(location)):
        x = func(location[i][0],location[i][1],X, Y)
        list.append(x)
    
    
    min = get_min(list)
    res = []
    for x in min:
        i = list.index(x)
        res.append(i+1)
        list[i] = '$$$'  #取代掉已经找到的,防止index找两次一样的
    
    
    for i in res:
        print(i)

    第二题

     

     

    ( 供复制)

    样例1输入

    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

    样例2输入

    1 3 8 0 0 10 10
    -1 -1 0 0 0 0 -1 -1 0 0 -1 -1 0 0 0 0
    
    def judge(x,y):
        if xl<=x<=xr and yd<=y<=yu:
            return 1
        else:
            return 0
    
    def stayornot(judgement,k):
        for i in range(0,len(judgement)-k+1):
            list = []
            sum = 0
            for j in range(k):
                list.append(judgement[i+j])
            for x in list:
                sum += x
            if sum == k:
                return 1
        return 0
    
    n, k, t, xl, yd, xr, yu = map(int, input().split())
    stay = 0
    nostay = 0
    for i in range(n):
        route = [int(i) for i in input().split()]
        judgement = []
        for i in range(0,t*2,2):
            judgement.append(judge(route[i],route[i+1]))
        sum = 0
        for x in judgement:
            sum += x
        
        s = stayornot(judgement, k)
        
        stay +=s
        if sum>=1:
            nostay+=1
    
    print(nostay)
    print(stay)
  • 相关阅读:
    C#判断是否运行在调试模式下
    [php] Interface abstract里面的私有方法 private method of interface and abstract class
    [html] Javascript warning and error of w3c
    [html] <a> and <input> can not click in IE6 when use png fixed IE6下png图片和png背景透明导致该区域的链接和按钮无效
    [Ubuntu] invalid environment block
    [Ubuntu] 分割与合并文件 Cut and mix the file
    [php] Treat an object like an array
    [eZ publish] How to add a element to an array.
    [html] PHP使用Google map web services来计算两点间的距离 Compute the distance between two place via Google map services in PHP
    [html] symbol of <b> and <strong>
  • 原文地址:https://www.cnblogs.com/This-is-Y/p/13681884.html
Copyright © 2020-2023  润新知