consolidate all repos to one for archive
This commit is contained in:
@@ -0,0 +1 @@
|
||||
.vscode/
|
||||
@@ -0,0 +1,2 @@
|
||||
Name of class
|
||||
algoritmi_in_tehnike_za_učinkovito_reševanje_problemov
|
||||
@@ -0,0 +1,31 @@
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
std::ifstream inputFile(argv[1]);
|
||||
|
||||
int boxSize, goldSize, goldValue, silverSize, silverValue;
|
||||
|
||||
while (inputFile >> boxSize >> goldSize >> goldValue >> silverSize >> silverValue)
|
||||
{
|
||||
int maxValue = 0;
|
||||
int goldCount = boxSize / goldSize;
|
||||
int silverCount = boxSize / silverSize;
|
||||
|
||||
for (size_t i = 0; i <= goldCount; i++)
|
||||
{
|
||||
for (size_t j = 0; j <= silverCount; j++)
|
||||
{
|
||||
if (i * goldSize + j * silverSize <= boxSize)
|
||||
{
|
||||
int value = i * goldValue + j * silverValue;
|
||||
maxValue = std::max(maxValue, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
printf("%d\n", maxValue);
|
||||
}
|
||||
inputFile.close();
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
CC=g++
|
||||
|
||||
CFLAGS= -std=c++23
|
||||
|
||||
INCLUDE_DIR= include
|
||||
|
||||
SRC_DIR= src
|
||||
|
||||
# Get all cpp files from src directory
|
||||
SRCS := $(wildcard $(SRC_DIR)/*.cpp)
|
||||
|
||||
all: main
|
||||
|
||||
main: main.cpp $(SRCS)
|
||||
$(CC) $(CFLAGS) -o3 -I$(INCLUDE_DIR) $(SRCS) main.cpp -o main
|
||||
|
||||
debug: main.cpp $(SRCS)
|
||||
$(CC) $(CFLAGS) -I$(INCLUDE_DIR) $(SRCS) -g main.cpp -o main
|
||||
|
||||
run: main
|
||||
./main testni_primer.txt
|
||||
|
||||
zip:
|
||||
zip -r main.zip main.cpp $(INCLUDE_DIR) $(SRC_DIR) makefile
|
||||
|
||||
clean:
|
||||
rm main
|
||||
@@ -0,0 +1,150 @@
|
||||
98514
|
||||
41219
|
||||
82500
|
||||
57792
|
||||
0
|
||||
0
|
||||
0
|
||||
52845
|
||||
0
|
||||
419573
|
||||
42165
|
||||
1304940
|
||||
57576
|
||||
912124
|
||||
0
|
||||
227070
|
||||
47034
|
||||
0
|
||||
179652
|
||||
87570
|
||||
13998
|
||||
50229
|
||||
86496
|
||||
447894
|
||||
145209
|
||||
51594
|
||||
0
|
||||
657514
|
||||
34933
|
||||
39862
|
||||
45037
|
||||
0
|
||||
30214
|
||||
56534
|
||||
95553
|
||||
0
|
||||
70963
|
||||
77934
|
||||
130685
|
||||
31474
|
||||
1272330
|
||||
29123
|
||||
0
|
||||
34508
|
||||
0
|
||||
40918
|
||||
0
|
||||
579620
|
||||
0
|
||||
49348
|
||||
78930
|
||||
13014
|
||||
265048
|
||||
0
|
||||
77754
|
||||
73140
|
||||
21167
|
||||
107215
|
||||
405405
|
||||
41922
|
||||
49786
|
||||
7015320
|
||||
0
|
||||
0
|
||||
375945
|
||||
73852
|
||||
77622
|
||||
425612
|
||||
49207
|
||||
361432
|
||||
288078
|
||||
772896
|
||||
68565
|
||||
149805
|
||||
33886
|
||||
0
|
||||
0
|
||||
164005
|
||||
0
|
||||
43421
|
||||
99820
|
||||
0
|
||||
142780
|
||||
0
|
||||
196428
|
||||
0
|
||||
6056
|
||||
0
|
||||
137752
|
||||
50248
|
||||
103104
|
||||
64334
|
||||
153592
|
||||
1579812
|
||||
0
|
||||
0
|
||||
0
|
||||
211640
|
||||
443205
|
||||
0
|
||||
393264
|
||||
32919
|
||||
16880
|
||||
18294
|
||||
40276
|
||||
0
|
||||
881610
|
||||
26249
|
||||
37131
|
||||
189091
|
||||
39028
|
||||
62931
|
||||
341024
|
||||
137775
|
||||
86122
|
||||
26344
|
||||
52560
|
||||
40260
|
||||
141336
|
||||
30116
|
||||
19673
|
||||
108855
|
||||
14736
|
||||
44739
|
||||
35921
|
||||
0
|
||||
0
|
||||
21741
|
||||
796614
|
||||
14821
|
||||
0
|
||||
42505
|
||||
70551
|
||||
1099353
|
||||
69234
|
||||
175172
|
||||
461208
|
||||
119460
|
||||
0
|
||||
113048
|
||||
66578
|
||||
9449
|
||||
47842
|
||||
205950
|
||||
57632
|
||||
12817440
|
||||
67035
|
||||
0
|
||||
39826
|
||||
61646
|
||||
@@ -0,0 +1,150 @@
|
||||
49119 20081 49257 44604 43241
|
||||
19850 15987 9654 15841 41219
|
||||
8592 7791 46164 2304 27500
|
||||
15084 3348 14448 7096 21253
|
||||
23173 34451 25089 30016 21150
|
||||
48856 49596 14484 49480 24236
|
||||
1535 5378 10713 12870 23219
|
||||
35296 6106 10569 35198 29106
|
||||
843 41109 40643 11753 5759
|
||||
49622 32273 22705 4383 38143
|
||||
9371 4823 42165 7060 41160
|
||||
22150 336 20076 5977 10411
|
||||
22273 6310 19192 12653 324
|
||||
9951 92 1998 67 6163
|
||||
15000 30822 13276 47807 27658
|
||||
49822 19177 29150 4805 22707
|
||||
35171 15870 23517 26367 35469
|
||||
28008 49308 38363 36227 25549
|
||||
34693 32171 24963 7959 44913
|
||||
10290 5125 32025 2897 29190
|
||||
22091 2964 943 17869 13055
|
||||
40032 28965 3779 11712 16743
|
||||
4807 620 7221 1611 36027
|
||||
6543 4094 9991 355 24883
|
||||
18034 5461 48403 15808 3611
|
||||
40977 12857 3001 11753 17198
|
||||
22616 28630 38829 45807 77
|
||||
44728 38384 21639 2242 34606
|
||||
27098 21694 3662 16308 34933
|
||||
4419 2529 9541 2288 39862
|
||||
40926 13375 8872 34586 45037
|
||||
45675 46925 8991 47372 32289
|
||||
39787 22030 30214 30698 14769
|
||||
16895 6121 28267 10602 19667
|
||||
40361 29950 34200 12941 31851
|
||||
1974 35822 33659 26463 22232
|
||||
7047 2419 23355 3699 47608
|
||||
25341 9595 38967 9544 14415
|
||||
44059 26124 7026 8068 26137
|
||||
7705 7371 18476 5141 31474
|
||||
22349 20860 27093 491 28274
|
||||
868 752 24381 446 29123
|
||||
43001 43092 35790 47762 10534
|
||||
42996 18430 17254 17590 2947
|
||||
24772 31342 35672 33188 20607
|
||||
27003 13834 40918 25063 8639
|
||||
1377 32226 19893 5421 21107
|
||||
29934 1488 28981 21557 33770
|
||||
31524 38708 9896 33642 40571
|
||||
40805 34097 49348 20447 152
|
||||
47800 17093 4801 22432 39465
|
||||
46015 39026 12281 33134 13014
|
||||
40252 5038 37864 8966 18968
|
||||
3546 19385 8236 4994 6909
|
||||
26259 14740 18466 7267 25918
|
||||
12863 12401 45627 4349 36570
|
||||
43353 41759 21131 38491 21167
|
||||
7387 6451 23517 1338 21443
|
||||
7321 2562 16999 645 36855
|
||||
45897 36129 27005 43221 41922
|
||||
34951 30425 49786 26355 36276
|
||||
26309 73 19487 14613 25504
|
||||
1219 27956 49321 12330 39000
|
||||
25110 48422 35170 46694 47951
|
||||
7243 722 11842 470 25063
|
||||
13452 11974 6792 5207 36926
|
||||
19590 2810 12937 17944 7579
|
||||
40028 35617 49669 3386 38692
|
||||
28394 21820 31181 27255 49207
|
||||
26587 8922 46144 3198 45179
|
||||
40831 7251 24697 306 2166
|
||||
10501 618 48306 6730 5789
|
||||
37196 16850 5885 10290 22855
|
||||
511 445 42392 147 49935
|
||||
42566 35629 33886 27561 1122
|
||||
24887 38462 47400 36577 36615
|
||||
10068 44872 6497 35021 35220
|
||||
18259 3905 36734 1916 17069
|
||||
22748 38717 24375 26125 5702
|
||||
39051 23088 43421 35577 31260
|
||||
45200 9877 24955 37448 33337
|
||||
15658 30507 1542 40216 15676
|
||||
27755 24800 7202 6140 35695
|
||||
34744 41840 30466 38690 47798
|
||||
8386 1919 49107 718 10628
|
||||
31597 40254 9846 44446 33860
|
||||
19865 16488 6056 18682 3708
|
||||
14988 18196 5681 49990 25981
|
||||
47459 10183 34438 44378 49973
|
||||
30712 15312 15179 12092 25124
|
||||
32676 6831 24454 3219 5288
|
||||
31924 15924 32167 29303 21635
|
||||
20725 2434 19199 6261 10038
|
||||
49417 39520 37093 861 27716
|
||||
21958 43861 31126 29691 13782
|
||||
25369 44206 13769 48243 9655
|
||||
31569 45624 3759 38286 23374
|
||||
32730 5579 42328 14839 15317
|
||||
601 542 37569 66 49245
|
||||
10041 49366 18871 14017 45656
|
||||
38649 1586 16386 26027 38823
|
||||
35662 35362 14153 10217 10973
|
||||
31394 31094 16880 15992 822
|
||||
8098 7360 18294 4349 12976
|
||||
42384 25506 5732 20097 20138
|
||||
29951 42527 19566 47555 30774
|
||||
6341 4515 35060 211 29387
|
||||
29468 25068 26249 26784 15140
|
||||
47023 35976 3020 30680 37131
|
||||
17338 2281 27013 12821 42442
|
||||
47133 44339 3431 37922 39028
|
||||
26834 16147 6143 7717 20977
|
||||
28004 3445 42628 4856 42202
|
||||
20347 6481 45925 14707 28140
|
||||
19294 6867 43061 15429 10174
|
||||
45913 32323 6697 15684 13172
|
||||
1165 343 17520 574 21612
|
||||
9702 9517 19508 3363 20130
|
||||
13582 971 10872 12166 42240
|
||||
5598 3950 20878 3146 30116
|
||||
28471 27087 19673 8093 4768
|
||||
19377 3428 21771 17846 8389
|
||||
26079 6884 822 22992 14736
|
||||
33312 32036 11747 30584 44739
|
||||
23409 12788 9714 16175 35921
|
||||
41677 42415 10343 45853 5542
|
||||
3153 29437 4608 28848 48813
|
||||
1387 851 21741 1084 21655
|
||||
43973 2013 37934 40251 28450
|
||||
21903 17094 14821 19235 12208
|
||||
4012 36877 27578 32982 11058
|
||||
28231 25254 10718 15299 42505
|
||||
46300 27677 10657 15246 23517
|
||||
3994 2626 7403 127 35463
|
||||
9033 3215 34617 7594 48746
|
||||
49311 48701 1912 10703 43793
|
||||
4383 1443 16015 348 38434
|
||||
187 111 49062 60 39820
|
||||
47838 49916 40568 49471 7705
|
||||
41728 8770 28262 20926 15646
|
||||
4198 1755 33289 3508 15419
|
||||
43854 23278 8582 35119 9449
|
||||
37698 29482 9461 18242 23921
|
||||
43547 8551 41190 19960 15138
|
||||
48453 33036 4733 22236 28816
|
||||
49723 39941 4545 48 12384
|
||||
47375 9257 13407 23532 3479
|
||||
1927 5943 38200 40579 718
|
||||
17317 15887 39826 15010 18418
|
||||
32826 15368 30823 26191 15650
|
||||
@@ -0,0 +1,95 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <fstream>
|
||||
|
||||
std::vector<std::vector<int>> vec;
|
||||
|
||||
bool test(int num)
|
||||
{
|
||||
int prev = 0;
|
||||
int count = 0;
|
||||
|
||||
for (size_t i = 0; i < vec.size(); i++)
|
||||
{
|
||||
for (size_t j = 0; j < vec[i].size(); j++)
|
||||
{
|
||||
if (vec[i][j] <= num)
|
||||
continue;
|
||||
|
||||
if (count == 0)
|
||||
{
|
||||
prev = vec[i][j];
|
||||
count++;
|
||||
}
|
||||
else if (count == 1)
|
||||
{
|
||||
if (prev != vec[i][j])
|
||||
return false;
|
||||
count = 0;
|
||||
}
|
||||
}
|
||||
if (count > 0)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
int alg(int start, bool s, int end, bool e)
|
||||
{
|
||||
if (end - start == 1)
|
||||
{
|
||||
if (s)
|
||||
return start;
|
||||
else if (e)
|
||||
return end;
|
||||
}
|
||||
int middle = (start + end) / 2;
|
||||
bool m = test(middle);
|
||||
|
||||
if (m == e)
|
||||
{
|
||||
return alg(start, s, middle, m);
|
||||
}
|
||||
else if (s == m)
|
||||
{
|
||||
return alg(middle, m, end, e);
|
||||
}
|
||||
|
||||
return middle;
|
||||
}
|
||||
|
||||
int start_alg(int num)
|
||||
{
|
||||
bool s = test(0);
|
||||
bool e = test(num);
|
||||
return alg(0, s, num, e);
|
||||
}
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
std::ifstream ifile(argv[1]);
|
||||
int size = 0;
|
||||
ifile >> size;
|
||||
|
||||
int num = 0;
|
||||
int max = 0;
|
||||
|
||||
vec.emplace_back(std::vector<int>());
|
||||
vec.emplace_back(std::vector<int>());
|
||||
|
||||
for (size_t i = 0; i < 2; i++)
|
||||
{
|
||||
for (size_t j = 0; j < size; j++)
|
||||
{
|
||||
ifile >> num;
|
||||
if (num > max)
|
||||
max = num;
|
||||
vec[i].push_back(num);
|
||||
}
|
||||
}
|
||||
|
||||
int fin = start_alg(max);
|
||||
std::cout << fin << "\n";
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
CC=g++
|
||||
|
||||
CFLAGS= -std=c++23
|
||||
|
||||
INCLUDE_DIR= include
|
||||
|
||||
SRC_DIR= src
|
||||
|
||||
# Get all cpp files from src directory
|
||||
SRCS := $(wildcard $(SRC_DIR)/*.cpp)
|
||||
|
||||
all: main run
|
||||
|
||||
main: main.cpp $(SRCS)
|
||||
$(CC) $(CFLAGS) -o3 -I$(INCLUDE_DIR) $(SRCS) main.cpp -o main
|
||||
|
||||
debug: main.cpp $(SRCS)
|
||||
$(CC) $(CFLAGS) -I$(INCLUDE_DIR) $(SRCS) -g main.cpp -o main
|
||||
|
||||
run: main
|
||||
./main testni_primer4.txt
|
||||
|
||||
zip:
|
||||
zip -r main.zip main.cpp $(INCLUDE_DIR) $(SRC_DIR) makefile
|
||||
|
||||
clean:
|
||||
rm main
|
||||
@@ -0,0 +1,4 @@
|
||||
test 1: 2
|
||||
test 2: 0
|
||||
test 3: 999492
|
||||
test 4: 999999579
|
||||
@@ -0,0 +1,3 @@
|
||||
5
|
||||
2 1 8 4 9
|
||||
9 4 1 2 8
|
||||
@@ -0,0 +1,3 @@
|
||||
8
|
||||
7 7 15 15 2 2 4 4
|
||||
5 5 3 3 9 9 1 1
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,11 @@
|
||||
10 8 10
|
||||
+ 4 5 4
|
||||
+ 6 8 2
|
||||
+ 3 0 6
|
||||
+ 7 4 4
|
||||
- 1
|
||||
+ 5 1 2
|
||||
- 3
|
||||
+ 4 0 10
|
||||
+ 2 0 4
|
||||
-6
|
||||
@@ -0,0 +1,10 @@
|
||||
8
|
||||
8
|
||||
6
|
||||
6
|
||||
7
|
||||
7
|
||||
8
|
||||
4
|
||||
4
|
||||
7
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,72 @@
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
|
||||
struct pillow
|
||||
{
|
||||
int x, y, s;
|
||||
};
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
std::ifstream in(argv[1]);
|
||||
if (!in.is_open())
|
||||
{
|
||||
std::cout << "Error opening file" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
int N, V, S;
|
||||
in >> N >> V >> S;
|
||||
|
||||
std::vector<std::multiset<int>> columns(S);
|
||||
char c;
|
||||
int row;
|
||||
std::vector<pillow> pillows;
|
||||
pillows.reserve(N);
|
||||
pillow p;
|
||||
int max_fall = 0;
|
||||
|
||||
for (size_t i = 0; i < N; i++)
|
||||
{
|
||||
in >> c;
|
||||
if (c == '+')
|
||||
{
|
||||
in >> p.x >> p.y >> p.s;
|
||||
p.s--;
|
||||
pillows.push_back(p);
|
||||
for (int j = p.y; j <= p.y + p.s; j++)
|
||||
{
|
||||
columns[j].insert(p.x);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
in >> row;
|
||||
pillow p = pillows[row - 1];
|
||||
for (int j = p.y; j <= p.y + p.s; j++)
|
||||
{
|
||||
columns[j].erase(columns[j].find(p.x));
|
||||
}
|
||||
}
|
||||
|
||||
for (auto &i : columns)
|
||||
{
|
||||
auto it = i.begin();
|
||||
if (it == i.end())
|
||||
{
|
||||
max_fall = V;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (*it > max_fall)
|
||||
max_fall = *it;
|
||||
}
|
||||
}
|
||||
std::cout << max_fall << std::endl;
|
||||
max_fall = 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
CC=g++
|
||||
|
||||
CFLAGS= -std=c++23
|
||||
|
||||
INCLUDE_DIR= include
|
||||
|
||||
SRC_DIR= src
|
||||
|
||||
# Get all cpp files from src directory
|
||||
SRCS := $(wildcard $(SRC_DIR)/*.cpp)
|
||||
|
||||
all: main run
|
||||
|
||||
main: main.cpp $(SRCS)
|
||||
$(CC) $(CFLAGS) -O3 -I$(INCLUDE_DIR) $(SRCS) main.cpp -o main
|
||||
|
||||
debug: main.cpp $(SRCS)
|
||||
$(CC) $(CFLAGS) -I$(INCLUDE_DIR) $(SRCS) -g main.cpp -o main
|
||||
|
||||
profile: main.cpp $(SRCS)
|
||||
$(CC) $(CFLAGS) main.cpp -g -pg -static-libgcc -o main
|
||||
|
||||
run: main
|
||||
time ./main ./examples/testni_primer2.txt > out.txt
|
||||
diff out.txt ./examples/testni_primer2_resitev.txt
|
||||
|
||||
zip:
|
||||
zip -r main.zip main.cpp $(INCLUDE_DIR) $(SRC_DIR) makefile
|
||||
|
||||
clean:
|
||||
rm main
|
||||
Binary file not shown.
@@ -0,0 +1,295 @@
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <vector>
|
||||
#include <array>
|
||||
|
||||
struct island
|
||||
{
|
||||
int L;
|
||||
int R;
|
||||
int time;
|
||||
};
|
||||
#define LEFT 0
|
||||
#define FROM_LEFT 1
|
||||
#define ACROSS 2
|
||||
#define RIGHT 3
|
||||
#define FROM_RIGHT 4
|
||||
#define MAX_NUM 10000000
|
||||
|
||||
std::vector<std::array<int, 5>> get_line_combinations(std::vector<island> &line)
|
||||
{
|
||||
|
||||
std::vector<std::array<int, 5>> comp(line.size(), std::array<int, 5>({0}));
|
||||
if (line.size() == 0)
|
||||
{
|
||||
return comp;
|
||||
}
|
||||
// going across the line
|
||||
std::sort(line.begin(), line.end(), [](const island &a, const island &b)
|
||||
{ return a.time < b.time; });
|
||||
for (size_t i = 0; i < line.size(); i++)
|
||||
{
|
||||
if (i == 0)
|
||||
{
|
||||
comp[i][ACROSS] = line[i].time + line[i].L + line[i].R;
|
||||
}
|
||||
else
|
||||
{
|
||||
comp[i][ACROSS] = comp[i - 1][ACROSS] + line[i].time;
|
||||
}
|
||||
}
|
||||
|
||||
// going back
|
||||
|
||||
std::sort(line.begin(), line.end(), [](const island &a, const island &b)
|
||||
{ return a.L < b.L; });
|
||||
|
||||
std::vector<bool> Lused(line.size(), false);
|
||||
int most_right_island = 0;
|
||||
int Lmin = MAX_NUM;
|
||||
int Lval = 0;
|
||||
int dist = 0;
|
||||
int Lindex = 0;
|
||||
int FLmin = 0;
|
||||
|
||||
std::vector<bool> Rused(line.size(), false);
|
||||
int most_left_island = line.size();
|
||||
int Rmin = MAX_NUM;
|
||||
int Rval = 0;
|
||||
int Rindex = 0;
|
||||
int FRmin = 0;
|
||||
|
||||
int tmp = 0;
|
||||
for (size_t i = 0; i < line.size(); i++)
|
||||
{
|
||||
if (i == 0)
|
||||
{
|
||||
for (size_t j = 0; j < line.size(); j++)
|
||||
{
|
||||
Lval = line[j].L + line[j].L + line[j].time;
|
||||
if (Lval < Lmin)
|
||||
{
|
||||
Lmin = Lval;
|
||||
Lindex = j;
|
||||
FLmin = line[j].L + line[j].time;
|
||||
}
|
||||
|
||||
Rval = line[j].R + line[j].R + line[j].time;
|
||||
if (Rval < Rmin)
|
||||
{
|
||||
Rmin = Rval;
|
||||
Rindex = j;
|
||||
FRmin = line[j].R + line[j].time;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (size_t j = 0; j < line.size(); j++)
|
||||
{
|
||||
if (!Lused[j])
|
||||
{
|
||||
if (j < most_right_island)
|
||||
{
|
||||
Lval = comp[i - 1][LEFT] + line[j].time;
|
||||
tmp = comp[i - 1][FROM_LEFT] + line[j].time;
|
||||
}
|
||||
else
|
||||
{
|
||||
dist = line[j].L - line[most_right_island].L;
|
||||
Lval = comp[i - 1][LEFT] + dist + dist + line[j].time;
|
||||
tmp = comp[i - 1][FROM_LEFT] + dist + line[j].time;
|
||||
}
|
||||
if (Lval < Lmin)
|
||||
{
|
||||
Lindex = j;
|
||||
Lmin = Lval;
|
||||
FLmin = tmp;
|
||||
}
|
||||
}
|
||||
if (!Rused[j])
|
||||
{
|
||||
|
||||
if (j > most_left_island)
|
||||
{
|
||||
Rval = comp[i - 1][RIGHT] + line[j].time;
|
||||
tmp = comp[i - 1][FROM_RIGHT] + line[j].time;
|
||||
}
|
||||
else
|
||||
{
|
||||
dist = line[j].R - line[most_left_island].R;
|
||||
Rval = comp[i - 1][RIGHT] + dist + dist + line[j].time;
|
||||
tmp = comp[i - 1][FROM_RIGHT] + dist + line[j].time;
|
||||
}
|
||||
|
||||
if (Rval < Rmin)
|
||||
{
|
||||
Rindex = j;
|
||||
Rmin = Rval;
|
||||
FRmin = tmp;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (Rindex < most_left_island)
|
||||
{
|
||||
most_left_island = Rindex;
|
||||
}
|
||||
Rused[Rindex] = true;
|
||||
comp[i][RIGHT] = Rmin;
|
||||
Rmin = MAX_NUM;
|
||||
comp[i][FROM_RIGHT] = FRmin;
|
||||
|
||||
if (Lindex > most_right_island)
|
||||
{
|
||||
most_right_island = Lindex;
|
||||
}
|
||||
Lused[Lindex] = true;
|
||||
comp[i][LEFT] = Lmin;
|
||||
Lmin = MAX_NUM;
|
||||
comp[i][FROM_LEFT] = FLmin;
|
||||
}
|
||||
|
||||
return comp;
|
||||
}
|
||||
|
||||
void print_deb(std::vector<int> &RESULT, std::vector<std::array<int, 2>> &A)
|
||||
{
|
||||
for (size_t i = 0; i < RESULT.size(); i++)
|
||||
{
|
||||
std::cout << RESULT[i] << " ";
|
||||
}
|
||||
|
||||
std::cout << std::endl
|
||||
<< std::endl;
|
||||
|
||||
for (size_t i = 0; i < A.size(); i++)
|
||||
{
|
||||
std::cout << A[i][0] << " " << A[i][1] << std::endl;
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
void increse(std::vector<std::array<int, 2>> &A)
|
||||
{
|
||||
for (size_t i = 0; i < A.size(); i++)
|
||||
{
|
||||
A[i][0]++;
|
||||
A[i][1]++;
|
||||
}
|
||||
}
|
||||
|
||||
void print_line(std::vector<island> &line)
|
||||
{
|
||||
for (size_t i = 0; i < line.size(); i++)
|
||||
{
|
||||
std::cout << line[i].L << " " << line[i].time << " " << line[i].R << std::endl;
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
void print_comp(std::vector<std::array<int, 5>> &comp)
|
||||
{
|
||||
for (size_t i = 0; i < comp.size(); i++)
|
||||
{
|
||||
std::cout << comp[i][LEFT] << " " << comp[i][FROM_LEFT] << " " << comp[i][ACROSS] << " " << comp[i][RIGHT] << " " << comp[i][FROM_RIGHT] << std::endl;
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
std::ifstream in(argv[1]);
|
||||
if (!in)
|
||||
{
|
||||
std::cout << "Cannot open file.\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
// N = visina
|
||||
int N;
|
||||
// sirina
|
||||
int M;
|
||||
// stevilo otokov
|
||||
int K;
|
||||
in >> N >> M >> K;
|
||||
M--;
|
||||
|
||||
std::vector<std::vector<island>> map(N, std::vector<island>());
|
||||
int x, y, t;
|
||||
for (size_t i = 0; i < K; i++)
|
||||
{
|
||||
|
||||
in >> x >> y >> t;
|
||||
x--;
|
||||
y--;
|
||||
map[x].emplace_back(island{y, M - y, t});
|
||||
}
|
||||
in.close();
|
||||
|
||||
std::vector<int> RESULT(K + 1, MAX_NUM);
|
||||
std::vector<std::array<int, 2>> A(K + 1, {MAX_NUM, MAX_NUM});
|
||||
RESULT[0] = 0;
|
||||
A[0][0] = 0;
|
||||
A[0][1] = M;
|
||||
std::vector<std::array<int, 2>> B = A;
|
||||
|
||||
int num_of_islands = 0;
|
||||
|
||||
std::vector<std::array<int, 5>> comp = get_line_combinations(map[0]);
|
||||
|
||||
num_of_islands = comp.size();
|
||||
|
||||
for (size_t i = 0; i < comp.size(); i++)
|
||||
{
|
||||
RESULT[i + 1] = std::min(RESULT[i + 1], comp[i][FROM_LEFT]);
|
||||
B[i + 1][0] = std::min(A[i + 1][0], comp[i][LEFT]);
|
||||
B[i + 1][1] = std::min(A[i + 1][1], comp[i][ACROSS]);
|
||||
}
|
||||
increse(B);
|
||||
A = B;
|
||||
|
||||
int prev = 0;
|
||||
int tmp_left = 0;
|
||||
int tmp_right = 0;
|
||||
int tmp2, tmp3;
|
||||
for (size_t i = 1; i < map.size(); i++)
|
||||
{
|
||||
comp = get_line_combinations(map[i]);
|
||||
num_of_islands += comp.size();
|
||||
for (size_t j = 1; j <= num_of_islands && comp.size() > 0; j++)
|
||||
{
|
||||
tmp_left = MAX_NUM;
|
||||
tmp_right = MAX_NUM;
|
||||
for (size_t k = 0; k < j && k < comp.size(); k++)
|
||||
{
|
||||
prev = j - (k + 1);
|
||||
RESULT[j] = std::min({RESULT[j], A[prev][0] + comp[k][FROM_LEFT], A[prev][1] + comp[k][FROM_RIGHT]});
|
||||
|
||||
tmp2 = std::min({A[j][0], A[prev][0] + comp[k][LEFT], A[prev][1] + comp[k][ACROSS]});
|
||||
if (tmp2 < tmp_left)
|
||||
{
|
||||
tmp_left = tmp2;
|
||||
}
|
||||
tmp3 = std::min({A[j][1], A[prev][0] + comp[k][ACROSS], A[prev][1] + comp[k][RIGHT]});
|
||||
if (tmp3 < tmp_right)
|
||||
{
|
||||
tmp_right = tmp3;
|
||||
}
|
||||
}
|
||||
B[j][0] = tmp_left;
|
||||
B[j][1] = tmp_right;
|
||||
}
|
||||
increse(B);
|
||||
A = B;
|
||||
}
|
||||
|
||||
for (size_t i = 1; i < RESULT.size(); i++)
|
||||
{
|
||||
std::cout << RESULT[i] << " ";
|
||||
}
|
||||
|
||||
std::cout << std::endl;
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
CC=g++
|
||||
|
||||
CFLAGS= -std=c++23
|
||||
|
||||
INCLUDE_DIR= include
|
||||
|
||||
SRC_DIR= src
|
||||
|
||||
# Get all cpp files from src directory
|
||||
SRCS := $(wildcard $(SRC_DIR)/*.cpp)
|
||||
|
||||
all: main run
|
||||
|
||||
main: main.cpp $(SRCS)
|
||||
$(CC) $(CFLAGS) -O3 -I$(INCLUDE_DIR) $(SRCS) main.cpp -o main
|
||||
|
||||
debug: main.cpp $(SRCS)
|
||||
$(CC) $(CFLAGS) -I$(INCLUDE_DIR) $(SRCS) -g main.cpp -o main
|
||||
|
||||
run: main
|
||||
./main test/testni_primer2.txt
|
||||
|
||||
zip:
|
||||
zip -r main.zip main.cpp $(INCLUDE_DIR) $(SRC_DIR) makefile
|
||||
|
||||
clean:
|
||||
rm main
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,6 @@
|
||||
4 4 5
|
||||
1 3 1
|
||||
1 2 9
|
||||
2 3 5
|
||||
3 2 6
|
||||
4 3 2
|
||||
@@ -0,0 +1 @@
|
||||
3 10 17 26 36
|
||||
@@ -0,0 +1,13 @@
|
||||
10 10 12
|
||||
2 2 11
|
||||
1 5 4
|
||||
3 3 55
|
||||
3 2 3
|
||||
3 7 22
|
||||
4 5 5
|
||||
6 2 3
|
||||
7 7 2
|
||||
8 2 2
|
||||
8 9 6
|
||||
9 5 7
|
||||
9 9 11
|
||||
@@ -0,0 +1 @@
|
||||
6 14 20 32 44 56 69 82 95 110 140 195
|
||||
@@ -0,0 +1,19 @@
|
||||
50 70 18
|
||||
1 5 1
|
||||
1 8 2
|
||||
3 3 3
|
||||
3 2 55
|
||||
6 2 11
|
||||
8 9 4
|
||||
9 4 3
|
||||
15 15 5
|
||||
13 4 13
|
||||
17 20 17
|
||||
30 5 22
|
||||
30 6 133
|
||||
30 7 44
|
||||
30 30 12
|
||||
44 44 34
|
||||
45 7 55
|
||||
48 5 87
|
||||
49 37 64
|
||||
@@ -0,0 +1 @@
|
||||
5 10 24 38 51 71 94 118 170 210 254 309 364 469 569 674 788 921
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,254 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <set>
|
||||
#include <fstream>
|
||||
#include <numeric>
|
||||
#include <chrono>
|
||||
#include <filesystem>
|
||||
|
||||
bool isDevider(std::multiset<int> &v, int n)
|
||||
{
|
||||
for (auto i : v)
|
||||
{
|
||||
if (i % n != 0)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
int findMaxSlow(std::multiset<int> &v)
|
||||
{
|
||||
int f = *(v.begin());
|
||||
for (size_t i = f; i >= 1; --i)
|
||||
{
|
||||
if (isDevider(v, i))
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::vector<int> findSlow(std::ifstream &file)
|
||||
{
|
||||
int lines = 0;
|
||||
file >> lines;
|
||||
char inst = 0;
|
||||
int num = 0;
|
||||
std::multiset<int> v;
|
||||
|
||||
std::vector<int> out_vec;
|
||||
|
||||
for (size_t i = 0; i < lines; i++)
|
||||
{
|
||||
file >> inst >> num;
|
||||
if (inst == '+')
|
||||
{
|
||||
v.insert(num);
|
||||
}
|
||||
else
|
||||
{
|
||||
v.erase(v.find(num));
|
||||
}
|
||||
out_vec.push_back(findMaxSlow(v));
|
||||
}
|
||||
return out_vec;
|
||||
}
|
||||
|
||||
int findMaxFast(std::multiset<int> &v)
|
||||
{
|
||||
int gretestCommonDevider = *(v.begin());
|
||||
for (auto i : v)
|
||||
{
|
||||
if (gretestCommonDevider != 0)
|
||||
{
|
||||
// GCD is deviding averithing and its not deviding the new number find the new devider
|
||||
if (i % gretestCommonDevider != 0)
|
||||
{
|
||||
gretestCommonDevider = std::gcd(gretestCommonDevider, i);
|
||||
// if GCD is one return 1 becouse 1 is min GCD
|
||||
if (gretestCommonDevider == 1)
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return gretestCommonDevider;
|
||||
}
|
||||
|
||||
std::vector<int> findFast(std::ifstream &file)
|
||||
{
|
||||
int lines = 0;
|
||||
file >> lines;
|
||||
char inst = 0;
|
||||
int num = 0;
|
||||
std::multiset<int> v;
|
||||
int devider = 0;
|
||||
|
||||
std::vector<int> out_vec;
|
||||
out_vec.reserve(lines);
|
||||
|
||||
file >> inst >> num;
|
||||
v.insert(num);
|
||||
devider = findMaxFast(v);
|
||||
|
||||
out_vec.push_back(devider);
|
||||
|
||||
int64_t add = 0;
|
||||
int64_t erase = 0;
|
||||
|
||||
for (size_t i = 1; i < lines; i++)
|
||||
{
|
||||
file >> inst >> num;
|
||||
|
||||
if (inst == '+')
|
||||
{
|
||||
// if you add number to the list just check if its devided by GCD if not find new one
|
||||
v.insert(num);
|
||||
if (devider != 0)
|
||||
{
|
||||
if (num % devider != 0)
|
||||
devider = std::gcd(num, devider);
|
||||
}
|
||||
else
|
||||
devider = std::gcd(num, devider);
|
||||
}
|
||||
else
|
||||
{
|
||||
v.erase(v.find(num));
|
||||
devider = findMaxFast(v);
|
||||
}
|
||||
|
||||
if (devider == 0)
|
||||
out_vec.push_back(1);
|
||||
else
|
||||
out_vec.push_back(devider);
|
||||
}
|
||||
|
||||
return out_vec;
|
||||
}
|
||||
|
||||
#if 0
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
if (argc != 3)
|
||||
return 1;
|
||||
int fast = std::stoi(argv[1]);
|
||||
|
||||
std::ifstream file(argv[2], std::ios::in);
|
||||
if (!file.is_open())
|
||||
return 1;
|
||||
|
||||
auto start = std::chrono::high_resolution_clock::now();
|
||||
|
||||
std::vector<int> out_vec;
|
||||
if (fast)
|
||||
out_vec = findFast(file);
|
||||
else
|
||||
out_vec = findSlow(file);
|
||||
|
||||
auto end = std::chrono::high_resolution_clock::now();
|
||||
|
||||
auto time = std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
|
||||
|
||||
std::ofstream out_file("out.txt", std::ios::out);
|
||||
if (!out_file.is_open())
|
||||
return 1;
|
||||
|
||||
for (auto i : out_vec)
|
||||
{
|
||||
out_file << i << std::endl;
|
||||
}
|
||||
|
||||
std::cout << time.count() << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
int main()
|
||||
{
|
||||
std::string directory_path = "sopek_marjetic/";
|
||||
|
||||
std::vector<std::string> files;
|
||||
std::vector<std::string> files_out;
|
||||
|
||||
// Iterate over the files in the directory
|
||||
for (const auto &entry : std::filesystem::directory_iterator(directory_path))
|
||||
{
|
||||
// Check if the entry is a regular file
|
||||
if (std::filesystem::is_regular_file(entry.path()))
|
||||
{
|
||||
if (entry.path().extension() == ".in")
|
||||
files.push_back(entry.path().string());
|
||||
else if (entry.path().extension() == ".out")
|
||||
files_out.push_back(entry.path().string());
|
||||
}
|
||||
}
|
||||
|
||||
std::sort(files.begin(), files.end());
|
||||
std::sort(files_out.begin(), files_out.end());
|
||||
printf(" %8s\t %8s\t %8s\t %s\n", "fast", "slow", "ratio", "file");
|
||||
|
||||
for (int i = 0; i < files.size(); i++)
|
||||
{
|
||||
std::vector<int> res_vec;
|
||||
std::vector<int> out_vec;
|
||||
int num = 0;
|
||||
std::ifstream out_file(files_out[i], std::ios::in);
|
||||
if (!out_file.is_open())
|
||||
continue;
|
||||
|
||||
while (!out_file.eof())
|
||||
{
|
||||
out_file >> num;
|
||||
out_vec.push_back(num);
|
||||
}
|
||||
|
||||
std::ifstream file(files[i], std::ios::in);
|
||||
if (!file.is_open())
|
||||
continue;
|
||||
|
||||
auto start = std::chrono::high_resolution_clock::now();
|
||||
res_vec = findFast(file);
|
||||
auto end = std::chrono::high_resolution_clock::now();
|
||||
auto fast = std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
|
||||
|
||||
for (int i = 0; i < res_vec.size(); i++)
|
||||
{
|
||||
if (res_vec[i] != out_vec[i])
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
file.seekg(0, std::ios::beg);
|
||||
|
||||
auto start1 = std::chrono::high_resolution_clock::now();
|
||||
res_vec = findSlow(file);
|
||||
auto end1 = std::chrono::high_resolution_clock::now();
|
||||
auto slow = std::chrono::duration_cast<std::chrono::milliseconds>(end1 - start1);
|
||||
|
||||
for (size_t i = 0; i < res_vec.size(); i++)
|
||||
{
|
||||
if (res_vec[i] != out_vec[i])
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (fast.count() == 0)
|
||||
fast = std::chrono::milliseconds(1);
|
||||
if (slow.count() == 0)
|
||||
slow = std::chrono::milliseconds(1);
|
||||
|
||||
float ratio = (float)slow.count() / (float)fast.count();
|
||||
|
||||
printf(" %8ld\t %8ld\t %8f\t %s\n", fast.count(), slow.count(), ratio, files[i].c_str());
|
||||
|
||||
file.close();
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,30 @@
|
||||
CC=g++
|
||||
|
||||
CFLAGS= -std=c++23
|
||||
|
||||
INCLUDE_DIR= include
|
||||
|
||||
SRC_DIR= src
|
||||
|
||||
# Get all cpp files from src directory
|
||||
SRCS := $(wildcard $(SRC_DIR)/*.cpp)
|
||||
|
||||
all: main
|
||||
|
||||
main: main.cpp $(SRCS)
|
||||
$(CC) $(CFLAGS) -O3 -I$(INCLUDE_DIR) $(SRCS) main.cpp -o main
|
||||
|
||||
debug: main.cpp $(SRCS)
|
||||
$(CC) $(CFLAGS) -I$(INCLUDE_DIR) $(SRCS) -pg -g main.cpp -o main
|
||||
|
||||
slow_run: main
|
||||
./main 0 sopek_marjetic/marjetice04.in
|
||||
|
||||
fast_run: main
|
||||
./main 1 sopek_marjetic/marjetice04.in
|
||||
|
||||
zip:
|
||||
zip -r main.zip main.cpp $(INCLUDE_DIR) $(SRC_DIR) makefile
|
||||
|
||||
clean:
|
||||
rm main
|
||||
@@ -0,0 +1,13 @@
|
||||
fast slow ratio file
|
||||
1 1 1.000000 sopek_marjetic/marjetice00.in
|
||||
2 156 78.000000 sopek_marjetic/marjetice01.in
|
||||
2 20 10.000000 sopek_marjetic/marjetice02.in
|
||||
230 147462 641.139160 sopek_marjetic/marjetice03.in
|
||||
2498 6306 2.524420 sopek_marjetic/marjetice04.in
|
||||
241 300236 1245.792480 sopek_marjetic/marjetice05.in
|
||||
242 944863 3904.392578 sopek_marjetic/marjetice06.in
|
||||
218 218 1.000000 sopek_marjetic/marjetice08.in
|
||||
223 227 1.017937 sopek_marjetic/marjetice09.in
|
||||
2120 4770 2.250000 sopek_marjetic/marjetice10.in
|
||||
249 37365 150.060242 sopek_marjetic/marjetice12.in
|
||||
242 22636 93.537193 sopek_marjetic/marjetice13.in
|
||||
@@ -0,0 +1,25 @@
|
||||
23
|
||||
+ 49140
|
||||
+ 920640
|
||||
- 49140
|
||||
- 920640
|
||||
+ 227220
|
||||
+ 545160
|
||||
- 545160
|
||||
- 227220
|
||||
+ 824460
|
||||
+ 107940
|
||||
- 824460
|
||||
+ 605220
|
||||
- 605220
|
||||
+ 732480
|
||||
- 107940
|
||||
- 732480
|
||||
+ 613200
|
||||
- 613200
|
||||
+ 293160
|
||||
+ 691320
|
||||
- 293160
|
||||
- 691320
|
||||
+ 394380
|
||||
- 394380
|
||||
@@ -0,0 +1,23 @@
|
||||
49140
|
||||
420
|
||||
920640
|
||||
1
|
||||
227220
|
||||
420
|
||||
227220
|
||||
1
|
||||
824460
|
||||
420
|
||||
107940
|
||||
420
|
||||
107940
|
||||
420
|
||||
732480
|
||||
1
|
||||
613200
|
||||
1
|
||||
293160
|
||||
840
|
||||
691320
|
||||
1
|
||||
394380
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user