zoukankan      html  css  js  c++  java
  • CCF202006-Python题解

    线性分类器

    试题编号: 202006-1
    试题名称: 线性分类器
    时间限制: 1.0s
    内存限制: 512.0MB

     

     题解:直线上大于0,直线下小于0,模拟一下

    '''
    9 3
    1 1 A
    1 0 A
    1 -1 A
    2 2 B
    2 3 B
    0 1 A
    3 1 B
    1 3 B
    2 0 A
    0 2 -3
    -3 0 2
    -3 1 1
    '''
     1 n,m=map(int, input().split())
     2 dots=[]
     3 # [[1, 1, 'A'], [2, 2, 'B'], [2, 3, 'B'], [2, 0, 'A']]
     4 for _ in range(n):
     5     tmp=input().split()
     6     tmp1=list(map(int, tmp[:-1]))
     7     tmp1.extend(tmp[-1])
     8     dots.append(tmp1)
     9 
    10 
    11 for  _ in range(m):
    12     s0,s1,s2=map(int, input().split())
    13     flag=[]
    14     find=1
    15     for d in dots:
    16         summ=s0+s1*d[0]+s2*d[1]
    17         if  dots.index(d)==0 and summ>0 :
    18             flag.append([summ,d[2]])
    19         if dots.index(d)==0 and summ<0 :
    20             flag.append([summ,d[2]])
    21             
    22         if (summ*flag[0][0]>0) and flag[0][1]!=d[2]: #同号,AB
    23             find=0
    24         elif (summ*flag[0][0]<0) and flag[0][1]==d[2]:
    25             find=0
    26 
    27     if find:
    28         print('Yes')
    29     else:
    30         print('No')  

     

    稀疏向量

    试题编号: 202006-2
    试题名称: 稀疏向量
    时间限制: 2.0s
    内存限制: 512.0MB

     

     题解:向量相乘的过程,这里不要报了,后面4个测试点n太大

    '''
    10 3 4
    4 5
    7  -3
    10 1
    1 10
    4 20
    5 30
    7 40
    
    '''
     1 n,a,b=map(int, input().split())
     2 ans={}
     3 for _ in range(a): #保存第一个向量
     4     index,value=map(int, input().split())
     5     ans[index]=[value]
     6 
     7 summ=0
     8 for _ in range(b):
     9     index2,value2=map(int, input().split())
    10     if index2 in ans.keys(): #维度相同才能乘
    11         summ+=ans[index2][0]*value2
    12         
    13 print(summ)
  • 相关阅读:
    Ubuntu中文乱码问题解决方案
    微软开业网站----精华 http://www.microsoft.com/opensource/directory.aspx
    微软开源项目
    cnblogs开源合集
    微软开源软件---管理员用的软件
    微软开源项目-codeflex项目介绍
    SQLServer 微软团队开源项目 (web 版?)
    流程引擎2-CCFLOW
    流程引擎1-高人
    sql web Admin 源码.net 升级
  • 原文地址:https://www.cnblogs.com/z-712/p/14607167.html
Copyright © 2011-2022 走看看