盘荣博
parent
321434f837
commit
2b2079026a
@ -1,2 +0,0 @@
|
||||
a=[0]*int(2e4)
|
||||
print(len(a))
|
@ -1,54 +0,0 @@
|
||||
from functools import cmp_to_key
|
||||
c=[[],[]]
|
||||
string=[[],[]]
|
||||
for i in range(2):
|
||||
a = eval(input())
|
||||
while a>0:
|
||||
s=input().split()
|
||||
s[1],s[2]=eval(s[1]),eval(s[2])
|
||||
c[i].append(s)
|
||||
string[i].append(s[0])
|
||||
a-=1
|
||||
def cmp(a,b):
|
||||
if a[1]>b[1]:
|
||||
return -1
|
||||
elif a[1]==b[1]:
|
||||
if a[2]<b[2] :
|
||||
return -1
|
||||
else:
|
||||
return 1
|
||||
else :
|
||||
return 1
|
||||
c[0]=sorted(c[0],key=cmp_to_key(cmp))
|
||||
# print(c[0])
|
||||
c[1]=sorted(c[1],key=cmp_to_key(cmp))
|
||||
# print(c[1])
|
||||
# m='123'
|
||||
# n='123'
|
||||
# print(m==n)
|
||||
st="lzr010506"
|
||||
s=set(string[0])&set(string[1])
|
||||
# for i in c[0]:
|
||||
# for j in c[1]:
|
||||
# if i[0] == j[0] :
|
||||
# s.append(j[0])
|
||||
# print(s)
|
||||
ans1=0
|
||||
ans2=0
|
||||
i=0
|
||||
while c[0][i][0] != st:
|
||||
# print(c[0][i][0])
|
||||
if c[0][i][0] in s:
|
||||
ans1+=1
|
||||
i+=1
|
||||
ans1= i+1-ans1
|
||||
i=0
|
||||
while c[1][i][0]!=st:
|
||||
# print(c[1][i][0])
|
||||
if c[1][i][0] in s:
|
||||
ans2+=1
|
||||
i+=1
|
||||
ans2=i+1-ans2
|
||||
# print(ans1,ans2)
|
||||
print(min(ans1,ans2))
|
||||
# print(c[0],'\n',c[1])
|
@ -1,18 +0,0 @@
|
||||
import heapq
|
||||
import ctypes
|
||||
a=int(input())
|
||||
b=input().split()
|
||||
for i in range(len(b)):
|
||||
b[i]=int(b[i])
|
||||
heapq.heapify(b)
|
||||
# print(b)
|
||||
sum=0
|
||||
while len(b) != 1:
|
||||
c,d=heapq.nsmallest(2,b)
|
||||
# heapq.heappop(b)
|
||||
# heapq.heappop(b)
|
||||
b.remove(c)
|
||||
b.remove(d)
|
||||
sum+=c+d
|
||||
heapq.heappush(b,c+d)
|
||||
print(sum)
|
@ -1,28 +0,0 @@
|
||||
import functools
|
||||
a,b =map(int, input().split(' '))
|
||||
nums=[]
|
||||
for i in range(b):
|
||||
m,n=map(int,input().split(' '))
|
||||
if m>n:continue;
|
||||
nums.append([m,n])
|
||||
def cmp(a,b):#升序
|
||||
if(a[0]>b[0]):
|
||||
return 1
|
||||
else :
|
||||
return -1#不变
|
||||
nums=sorted(nums,key=functools.cmp_to_key(cmp))
|
||||
# for i in nums:
|
||||
# print(i)
|
||||
sum = 0
|
||||
start,end=nums[0][0],nums[0][1]
|
||||
count=1
|
||||
while count<len(nums):
|
||||
if nums[count][0]>=start and nums[count][0]<=end:
|
||||
if end<=nums[count][1]:
|
||||
end=nums[count][1]
|
||||
else :
|
||||
sum+=end-start+1
|
||||
start=nums[count][0];end=nums[count][1]
|
||||
count+=1
|
||||
sum+=end-start+1
|
||||
print(a-sum+1)
|
@ -1,7 +0,0 @@
|
||||
a,b =map(int, input().split(' '))
|
||||
nums=[]
|
||||
for i in range(b):
|
||||
m,n=map(int,input().split(' '))
|
||||
nums.extend(range(m,n+1))
|
||||
nums=set(nums)
|
||||
print(a+1-len(nums))
|
@ -0,0 +1,68 @@
|
||||
import pandas as pd
|
||||
<<<<<<< HEAD
|
||||
import numpy as np
|
||||
from scipy.stats import zscore
|
||||
from sklearn.decomposition import PCA
|
||||
from scipy.stats import zscore
|
||||
import matplotlib.pyplot as plt
|
||||
from matplotlib.pyplot import ylabel
|
||||
df = pd.read_excel("棉花产量论文作业的数据.xlsx")
|
||||
# plt.plot(df["年份"],df["单产"])
|
||||
plt.rcParams['font.sans-serif']="SimHei"
|
||||
# plt.rcParams['size'] =10
|
||||
# plt.ylabel('单产')
|
||||
# plt.xlabel('年份')
|
||||
|
||||
# print(df)
|
||||
d = df.to_numpy()[:,1:]
|
||||
print(d)
|
||||
plt.subplot(4,1,1)
|
||||
plt.scatter(d[:,:1],d[:,1:2],c='r')
|
||||
ylabel('原始数据'),plt.title("单产和种子费用的关系")
|
||||
#公式调用标准化,遵守标准正态分布
|
||||
data = zscore(d)
|
||||
print(data)
|
||||
plt.subplot(4,1,2)
|
||||
plt.scatter(data[:,:1],data[:,1:2],c='b',)
|
||||
ylabel('zscore')
|
||||
|
||||
print(d.max(axis=0))
|
||||
print(d.std(axis=0))
|
||||
print(d.mean(axis=0))
|
||||
#手写标准正态分布
|
||||
data1=(d-d.mean(axis=0))/d.std(axis=0)
|
||||
print(data1)
|
||||
plt.subplot(4,1,3)
|
||||
plt.scatter(data1[:,:1],data1[:,1:2],c='y')
|
||||
ylabel('手写标准正态分布')
|
||||
|
||||
data2=(d-d.min(axis=0))/(d.max(axis=0)-d.min(axis=0))
|
||||
plt.subplot(4,1,4)
|
||||
plt.scatter(data2[:,:1],data2[:,1:2],c='g')
|
||||
plt.xlabel('压缩到0~1')
|
||||
print(data==data1)
|
||||
|
||||
|
||||
# plt.savefig("shuju.jpg",dpi=2000)
|
||||
# plt.show()
|
||||
md= PCA().fit(data)
|
||||
cf = np.cov(data.T)#求协方差矩阵
|
||||
print(cf)
|
||||
c, d= np.linalg.eig(cf)
|
||||
print("特征值:\n",c)
|
||||
print(md.explained_variance_)
|
||||
e=c/c.sum()
|
||||
# for _ in range(len(e)):
|
||||
# if(_!=0):
|
||||
# e[_]+=e[_-1]
|
||||
print('贡献率:')
|
||||
print(e)
|
||||
print(md.explained_variance_ratio_)
|
||||
print('特征向量:')
|
||||
print(d.T)
|
||||
print(md.components_)
|
||||
print(md.components_-d.T<=0.1)
|
||||
|
||||
plt.savefig("shuju.jpg",dpi=2000)
|
||||
plt.show()
|
||||
|
Loading…
Reference in new issue