[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
Solve this faggots
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 24
Thread images: 5
File: 2a.gif (3 KB, 228x191) Image search: [Google]
2a.gif
3 KB, 228x191
Solve this faggots
>>
don't tell me what to do
>>
bcdea
>>
>>53923637
Wrong, the answer sheet says abcde
>>
Aebcd
>>
bcdea
>>
Summon Satan and have him at all points at once
>>
File: 1456615716748.png (18 KB, 250x250) Image search: [Google]
1456615716748.png
18 KB, 250x250
>>53924053
>>
>>53923660
>have abcde
>exchange ab for ea
>get better solution
>>
File: uematsu.jpg (7 KB, 271x186) Image search: [Google]
uematsu.jpg
7 KB, 271x186
A E D B C at 250 cost

Since there are only 5 nodes, it's perfectly acceptable to brute force the solution.
Since the travel costs are symmetrical, the number of solutions is always divisible by 2 (each solution can be reversed)
This example has exactly 2 solutions, no less and no more.
Starting at A makes sense, but doesn't have to. In this example you could also start at C.
Branch and bound is my algorithm of choice in case the number of nodes gets too great, but isn't necessary here.

#include <stdio.h>
#include <stdlib.h>

#define INF 999 /* not max_int to prevent overflow */
#define START 0 /* fixed start because symmetric travel costs */
#define NODES "ABCDE"
#define SIZE 5

int main(void) {
int matrix[SIZE][SIZE] = {
{INF,100,125,100, 75},
{100,INF, 50, 75,125},
{125, 50,INF,100,125},
{100, 75,100,INF, 50},
{ 75,125,125, 50,INF}
};
int b, c, d, e, w;
int cheapest = INF * INF;

for(b = 0; b < SIZE; b++) {
if(START == b) {
continue;
}
for(c = 0; c < SIZE; c++) {
if(c == START || c == b) {
continue;
}
for(d = 0; d < SIZE; d++) {
if(d == START || d == b || d == c) {
continue;
}
for(e = 0; e < SIZE; e++) {
if(e == START || e == b || e == c || e == d) {
continue;
}
w = matrix[START][b] + matrix[b][c] + matrix[c][d] + matrix[d][e];
if(w < cheapest) {
cheapest = w;
printf("%c %c %c %c %c = %d\n", NODES[START], NODES[b], NODES[c], NODES[d], NODES[e], w);
}
}
}
}
}

return EXIT_SUCCESS;
}


Fuck performance. All hail nested loops.
>>
>>53925054
this is the grossest way to brute force this
>>
>>53923596
dijiskstra's theorem
/thread
>>
File: saber.jpg (50 KB, 600x450) Image search: [Google]
saber.jpg
50 KB, 600x450
>>53925070
Deal with it. Only 4! attempts necessary.
>>
File: scoff.png (1 MB, 1920x1080) Image search: [Google]
scoff.png
1 MB, 1920x1080
>he didn't learn graph algorithms in college
lmao

http://algs4.cs.princeton.edu/40graphs/
>>
>>53923596
CBDEA
Uses minimum number of edges, and each edge used has weight strictly less than any unused edge.
>>
>>53923596
What is this even
>>
>>53925516
network optimization

step it up senpai
>>
>>53925516
Find the minimum weight path that hits each vertex.
>>
>>53925523
Def out of my league senpai
>>
Hail Satan
>>
>>53925072
Except that this is the travelling salesman problem, not going from one vertex to another
>>
>>53925054
>for{for{for{for
cringe
>>
Ptreyy sure I solvbed this in 3rd year CS
>>
aedbc=250 using the 'select next shortest edge' method (I forgot the name of the algorithm);

[e,d],[b,c]
+[a,e],[b,d]
solved in 2 iterations.
Thread replies: 24
Thread images: 5

banner
banner
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.