两次DFS求树直径方法见 这里. 这里的直径是指最长链包含的节点个数,而上一题是指最长链的路径权值之和,注意区分. K <= R: ans = K − 1; K > R: ans = R − 1 + ( K − R ) ∗ 2; #include <cstdio> #include <cstring> #include <cstdlib> #include <algorithm> using namespace std; ; struct n
python中对两个 list 求交集,并集和差集: 1.首先是较为浅白的做法: >>> a=[1,2,3,4,5,6,7,8,9,10] >>> b=[1,2,3,4,5] >>> intersection=[v for v in a if v in b] >>> intersection [1, 2, 3, 4, 5] >>> union=b.extend([v for v in a]) >>>
题目相对简单: package naizi; public class Circle { //私有成员及构造方法 private Point center; private int r; Circle(int rr,Point Cc){ this.r=rr; this.center=Cc; } public void showInfo(){ //打印信息 System.out.println("center=("+center.getx()+","+center.g
def diff(listA,listB): #求交集的两种方式 retA = [i for i in listA if i in listB] retB = list(set(listA).intersection(set(listB))) print "retA is: ",retA print "retB is: ",retB #求并集 retC = list(set(listA).union(set(listB))) print "retC1 is
B. Our Tanya is Crying Out Loud time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Right now she actually isn't. But she will be, if you don't solve this problem. You are given integers n, k,
(1)获取两个时间相差天数(没有上午下午区分) var d1=ABS_DATESTRING(FStartTime,'yyyy/MM/dd'); var d2=ABS_DATESTRING(FEndTime,'yyyy/MM/dd'); var date1= new Date(d1); var date2=new Date(d2); var time=date2.getTime()-date1.getTime(); var day=time/(1000*60*60*24);day (2)求历时几小