3.18

今日代码量:100

今日所用时间:1h

今日博客:1

今天写的代码主要是matlab和python的下面展示一下今日的代码:

s=int(input())
a=0
b=0
dict={}
for i in range(0,s):
    t=input()
    t=eval(t)
    dict.update(t)
for key in dict.keys():
    c=len(dict[key])
    a=a+c
    for key2 in dict[key].keys():
        d=dict[key][key2]
        b=b+d
print(str(s)+" "+str(a)+" "+str(b))
s= str(input())
m=s.split()
o=""
for i in range(len(m)-1,-1,-1):
  o=o+m[i]
print(o)
print(m[:])
d=str(m[-1])
for i in range(len(m)-1):
  d=d+" "+m[-i-2]
print(d)
from collections import OrderedDict
a= input()
b=input().split(" ")
c=input().split(" ")
d=input().split(" ")
e=input()
list_1="".join(OrderedDict.fromkeys(a))
st_split = list(b)
while "" in st_split:
    st_split.remove("")
list_2 = list(set(st_split))
list_2.sort(key=st_split.index)
re=len(list_1)+len(list_2)
print("Total: "+str(re))
while "" in c:
    c.remove("")
result3=list(c)+d
st_split2 = list(d)
list2=list(set(list_2+list(list_1)).difference(set(result3)))
l2 = list(set(result3))
l2.sort(key=result3.index)
list4=[]
list4=list(set(l2) & set(c))
list41=list(set(list4) & set(d))
list5=list(set(l2).difference(set(c)))
list6=list(set(l2).difference(set(d)))
list7=list(set(list5).union(set(list6)))
print('Not in race: {0}, num: {1}'.format(sorted(list2),str(len(list2))))
print('All racers: {0}, num: {1}'.format(sorted(l2),str(len(l2))))
print('ACM + English: {0}, num: {1}'.format(sorted(list41),str(len(list41))))
print('Only ACM: {0}'.format(sorted(list6)))
print('Only English: {0}'.format(sorted(list5)))
print('ACM Or English: {0}'.format(sorted(list7)))
list_4=list(list_1)
if e in list_4:
    list_4.remove(e)
    print (sorted(list_4))
if e in list_2:
    list_2.remove(e)
    print (sorted(list_2))

 

function [section]=JT(fx,x0,h0,t)
%%%输入目标函数fx,初始点x0,初始步长h0和加倍系数t;
%%%采用进退法确定搜索区间[a,b];
%%%输出搜索区间。
f=inline(fx);
k=0;    %%计数器,同时也做指示器:如果第1次目标函数就没有下降,将作为反向搜索的指示标记;
h=h0;
a=x0;
judge=1;    %%循环判断器;    
while judge==1   %%ture,继续循环
    x1=x0+h; 
    k=k+1;
    if  f(x1)<f(x0)   %%判断搜索方向,保证是下降方向;
        h=t*h;        %%加大步长,一般情况下选择加倍系数为2;
        a=x0;         %%最值区间的一端;
        x0=x1;        %%更新初始点;
    else
       if k==1      %%判断初始方向是否错误;
          h=-h;      %%方向错误,选择反方向;
       else                
           judge=0;    %%error,不满足循环条件,将跳出循环。
       end
    end
end
 m=min(a,x1);
 n=max(a,x1);
section=sprintf('[%.4f,%.4f]',m,n);  %%格式化输出区间

 

posted @ 2024-03-18 21:49  艾鑫4646  阅读(1)  评论(0编辑  收藏  举报