Skip to content

Commit 812ad57

Browse files
committed
frame
1 parent 5d93e69 commit 812ad57

File tree

6 files changed

+63
-0
lines changed

6 files changed

+63
-0
lines changed

list/Makefile

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
TARGET=$(shell basename `pwd`)
2+
SOURCES=$(wildcard *.cpp)
3+
OBJECTS=$(SOURCES:%.cpp=%.o)
4+
5+
all: $(TARGET)
6+
7+
$(OBJECTS): $(SOURCES)
8+
9+
$(TARGET): $(OBJECTS)
10+
$(CXX) -o $(TARGET) $(LDFLAGS) $(OBJECTS) $(LOADLIBES) $(LDLIBS)
11+
12+
clean:
13+
$(RM) $(OBJECTS) $(TARGET)
14+
15+
.PHONY: all clean

list/list

22.6 KB
Binary file not shown.

list/list.cpp

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#include <vector>
2+
#include <iostream>
3+
4+
using namespace std;
5+
6+
static const int MAX = 2147483647;
7+
8+
int main () {
9+
int n, k;
10+
cin >> n >> k;
11+
12+
vector <int> q;
13+
vector <int> mins;
14+
15+
int tmin = MAX;
16+
17+
for (int i = 0; i < k; i++) {
18+
int t;
19+
cin >> t;
20+
tmin = t < tmin ? t : tmin;
21+
q.push_back(t);
22+
}
23+
24+
mins.push_back(tmin);
25+
26+
for (int i = k; i < n; i++) {
27+
tmin = MAX;
28+
int t;
29+
cin >> t;
30+
q.push_back(t);
31+
if (t <= mins[i - k])
32+
mins.push_back(t);
33+
else if (q[0] == mins[i - k]) {
34+
for (int j = 1; j <= k; j++) {
35+
tmin = q[j] < tmin ? q[j] : tmin;
36+
}
37+
mins.push_back(tmin);
38+
} else mins.push_back(mins[i - k]);
39+
q.erase(q.begin());
40+
}
41+
42+
for (int i = 0; i < n - k + 1; i++) {
43+
cout << mins[i] << endl;
44+
}
45+
return 0;
46+
}

list/list.i

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
7 2
2+
1 3 2 4 5 3 1

list/list.o

37.1 KB
Binary file not shown.

list/list.py

Whitespace-only changes.

0 commit comments

Comments
 (0)