Description Last September, Hangzhou raised the taxi fares. The original flag-down fare in Hangzhou was 10 yuan, plusing 2 yuan per kilometer after the first 3km and 3 yuan per kilometer after 10km. The waiting fee was 2 yuan per five minutes. Passen
1.安装matplotlib pip3 install matplotlib sudo apt install python3-tk 2.分段函数 from pylab import * x = linspace(0,8,200) cond = [True if (i > 2 and i < 5) else False for i in x] y = sin(x)*(x<2)+cos(x)*cond + x*(x>5) plot(x,y),show() 3.
参考这篇文章的代码封装了一个类似Matlab中的magic函数,用来生成魔方矩阵. #!/usr/bin/env python # -*- coding: utf-8 -*- import numpy as np def magic(n): row,col=0,n//2 magic=[] for i in range(n): magic.append([0]*n) magic[row][col]=1 for i in range(2,n*n+1): r,l=(row-1+n)%n,(col+1)
更新:x1,y1,x2,y2不用long long 会wa.. #include<iostream> #include<cstring> #include<cstdio> #include<algorithm> using namespace std; #define maxn 200005 #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 #define ll long long l
1.绘制分段函数:y=4sin(4πt)-sgn(t-0.3)-sgn(0.72-t) import numpy as npimport matplotlib.pyplot as plt#绘制分段函数:y=4sin(4πt)-sgn(t-0.3)-sgn(0.72-t) def sgn(x): if x > 0: return 1 elif x < 0: return -1 else: return 0 t = np.arange(0, 1, 0.01)y = []for i in t: y_