Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c09880c

Browse files
Create vmware.md
1 parent aa158fa commit c09880c

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

‎src/vmware.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
```python
2+
"""第一题: 线段数和三角形数"""
3+
n = int(input())
4+
5+
if n == 1:
6+
print(0, 0)
7+
elif n == 2:
8+
print(1, 0)
9+
elif n == 3:
10+
print(3, 1)
11+
else:
12+
# print(int(6+(n-4)/2*(2+(n-4)*2)), int(6+(n-4)/2*(2+(n-4)*2))-2)
13+
print((n-3)*3+3, (n-3)*3+1)
14+
15+
16+
17+
"""第二题:最小交换次数"""
18+
n = int(input())
19+
tmp = input().split()
20+
nums = [int(i) for i in tmp]
21+
length = len(nums)
22+
def sort1(nums):
23+
res = 0
24+
for i in range(length):
25+
swapped = False
26+
for j in range(length-1):
27+
if nums[j] > nums[j+1]:
28+
swapped = True
29+
nums[j], nums[j+1] = nums[j+1], nums[j]
30+
res += 1
31+
if not swapped:
32+
break
33+
return res
34+
def sort2(nums):
35+
res = 0
36+
for i in range(length):
37+
swapped = False
38+
for j in range(length-1):
39+
if nums[j] < nums[j+1]:
40+
swapped = True
41+
nums[j], nums[j+1] = nums[j+1], nums[j]
42+
res += 1
43+
if not swapped:
44+
break
45+
return res
46+
47+
print(min(sort1(nums), sort2(nums)))
48+
49+
50+
51+
52+
"""第三题: 搬家"""
53+
tmp = input().split()
54+
N, W = int(tmp[0]), int(tmp[1])
55+
sums = 0
56+
for i in range(N):
57+
sums += int(input())
58+
if sums == 0:
59+
print(0)
60+
else:
61+
if sums <= W:
62+
print(1)
63+
else:
64+
print(sums//W + 1)
65+
```

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /