File tree Expand file tree Collapse file tree 3 files changed +70
-0
lines changed
Expand file tree Collapse file tree 3 files changed +70
-0
lines changed Original file line number Diff line number Diff line change 1+ def main ():
2+ expression = input ()
3+ numList = expression .split ('-' )
4+ totalSum = 0
5+ totalMinus = []
6+
7+
8+ for i in numList [0 ].split ('+' ):
9+ totalSum += int (i )
10+
11+ for i in range (1 , len (numList )):
12+ totalMinus .append (numList [i ].split ('+' ))
13+
14+ for j in totalMinus .pop ():
15+ totalSum -= int (j )
16+
17+ print (totalSum )
18+
19+ if __name__ == "__main__" :
20+ main ()
Original file line number Diff line number Diff line change 1+ def main ():
2+ N , K = map (int , input ().split ())
3+ dp = [[0 ] * (N + 1 ) for _ in range (K + 1 )]
4+
5+ for i in range (K + 1 ):
6+ dp [i ][0 ] = 1
7+
8+ for i in range (1 , K + 1 ):
9+ for j in range (1 , N + 1 ):
10+ dp [i ][j ] = (dp [i - 1 ][j ] + dp [i ][j - 1 ]) % 1000000000
11+
12+ print (dp [K ][N ])
13+
14+
15+
16+ if __name__ == '__main__' :
17+ main ()
Original file line number Diff line number Diff line change 1+ import sys
2+ from collections import defaultdict
3+
4+ sys .setrecursionlimit (10 ** 6 )
5+ count = 0
6+
7+ def main ():
8+ input = sys .stdin .readline
9+ N , W = map (int , input ().split ())
10+
11+ tree = defaultdict (list )
12+
13+ for _ in range (N - 1 ):
14+ u , v = map (int , input ().split ())
15+ tree [u ].append (v )
16+ tree [v ].append (u )
17+
18+ def dfs (node , parent ):
19+ global count
20+ isLeaf = True
21+ for child in tree [node ]:
22+ if child != parent :
23+ isLeaf = False
24+ dfs (child , node )
25+ if isLeaf :
26+ count += 1
27+
28+ dfs (1 , - 1 )
29+
30+ print (W / count )
31+
32+ if __name__ == '__main__' :
33+ main ()
You can’t perform that action at this time.
0 commit comments