添加代码

pull/6/head
p3itgm2rp 7 months ago
commit 910206eb1b

3
.idea/.gitignore vendored

@ -0,0 +1,3 @@
# 默认忽略的文件
/shelf/
/workspace.xml

@ -0,0 +1,12 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="PyPackageRequirementsInspection" enabled="true" level="INFORMATION" enabled_by_default="true">
<option name="ignoredPackages">
<value>
<list size="0" />
</value>
</option>
</inspection_tool>
</profile>
</component>

@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.11 (mycode)" project-jdk-type="Python SDK" />
</project>

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/mycode.iml" filepath="$PROJECT_DIR$/.idea/mycode.iml" />
</modules>
</component>
</project>

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

@ -0,0 +1,2 @@
a=[0]*int(2e4)
print(len(a))

@ -0,0 +1,54 @@
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])

@ -0,0 +1,18 @@
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)

@ -0,0 +1,28 @@
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)

@ -0,0 +1,7 @@
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,7 @@
**三个文件夹**
数据可视化:暂时没有文件。
图:其中包括最短路径和最小生成树的展示
线性规划: 使用scipy库便且使用scipy的optimize模块下的linprog函数numpy函数统一操作数据以及使用matplotlib库下的pyplot模块

@ -0,0 +1,9 @@
import pandas as pd
import matplotlib.pyplot as plt
df = pd.read_excel("棉花产量论文作业的数据.xlsx")
plt.plot(df["年份"],df["单产"])
plt.rcParams['font.sans-serif']="SimHei"
plt.ylabel('单产')
plt.xlabel('年份')
plt.show()
print(df)

@ -0,0 +1,16 @@
import numpy as np
import pylab as pl
from scipy import interpolate
import matplotlib.pyplot as plt
x = np.linspace(0,2*np.pi+np.pi/4,10)
x1 = np.linspace(0,2*np.pi+np.pi/4,100)#num个0~2*Pi+Pi/4的范围的点
y = np.sin(x)
y1= np.sin(x1)
plt.xlabel(f"安培/A")
plt.ylabel(f'伏特/V')
linear_ = interpolate.interp1d(x,y)
print(linear_(x1))
plt.rcParams['font.sans-serif'] = ['SimSun']#设置字体
plt.plot(x,y,'o',label=f"原始数据")
plt.plot(x1,linear_(x1),"*",label="线性插入")
pl.show()

@ -0,0 +1,27 @@
from scipy import optimize
import numpy as np
c= np.array([-1,4])
A=np.array([[-3,1],[1,2]])
b=np.array([6,4])#小于关系
Aeq=np.array([[1,1,1]])#相等
beq = np.array([7])#
bounds = ((None,None),(-3,None))
res = optimize.linprog(c,A,b,None,None,bounds=bounds)
print("目标函数最小值:",res.fun)#目标函数最优解
print("最优解",res.x)#求得的最优解
c = [-1,2,3]
A=[[-2,1,1],[3,-1,-2]]
b=[[9],[-4]]
Aeq =[[4,-2,-1]]
beq=[-6]
LB=[-10,0,None]
UB = [None]*len(c)
print(UB)
bound = tuple(zip(LB,UB))
print(zip(LB,UB),'\n',bound)
res = optimize.linprog(c,A,b,Aeq,beq,bounds=bound)
print("函数的最小值为",res.fun)
print("最优解为:",res.x)
Loading…
Cancel
Save