Niestety, nie byliśmy w stanie w pełni poprawnie wyświetlić tego pliku, ponieważ nie jest zakodowany w UTF-8.
Możesz pobrać ten plik i spróbować otworzyć go samodzielnie.
#include <iostream>
#include <vector>
#include "maklib.h"
#include "message.h"
using namespace std;
#define LL long long
LL max_podciag(LL from, LL to)
{
LL w = 0;
LL wyn = 0;
for (LL i = from; i <= to; i++)
{
if (w > 0)
w += ElementAt(i);
else
w = ElementAt(i);
if (w > wyn)
wyn = w;
}
return wyn;
/*LL start = from;
LL len = 1;
LL sum = ElementAt(from);
LL curStart = from;
LL curLen = 1;
LL curSum = ElementAt(from);
for (LL i = from + 1; i <= to; i++)
{
if (ElementAt(i) >= curSum + ElementAt(i))
{
curStart = i;
curLen = 1;
curSum = ElementAt(i);
}
else
{
curLen++;
curSum += ElementAt(i);
}
if ((curSum > sum) ||
(curSum == sum && curLen < len) ||
(curSum == sum && curLen == len && curStart < start))
{
start = curStart;
len = curLen;
sum = curSum;
}
}
return sum;*/
}
int main()
{
if (MyNodeId() == 0)
{
cout << max_podciag(1, Size());
}
return 0;
/*
LL skok;
LL result;
skok = Size() / NumberOfNodes();
LL* from = 0x0;
LL* to = 0x0;
LL starting = MyNodeId() == 0 ? 1 : (MyNodeId() * (skok + 1) + 1);
if (MyNodeId() == NumberOfNodes() - 1) //ostatni
skok = Size() - (MyNodeId() * skok + 1);
LL max_num = max(starting, starting + skok, from, to);
//cout << "Start from: " << starting << " end: " << starting + skok << " Max sum: " << max_num << " From: " << *from << " To: " << *to;
if (MyNodeId() > 0) {
PutLL(0, max_num);
PutLL(0, *from);
PutLL(0, *to);
Send(0);
}
else
{
result = max_num;
LL poprzednie_from = *from, poprzednie_to = *to;
for (int i = 1; i < NumberOfNodes(); ++i) {
int instancja = Receive(i);
LL max_instancji = GetLL(instancja);
LL from_instacji = GetLL(instancja);
LL to_instacji = GetLL(instancja);
if (poprzednie_to + 1 == from_instacji) //takie same ko�ce, sklejamy
result += max_instancji;
else if (max_instancji >= result)
result = max_instancji;
poprzednie_from = from_instacji;
poprzednie_to = to_instacji;
}
cout << result;
}
return 0;*/
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | #include <iostream> #include <vector> #include "maklib.h" #include "message.h" using namespace std; #define LL long long LL max_podciag(LL from, LL to) { LL w = 0; LL wyn = 0; for (LL i = from; i <= to; i++) { if (w > 0) w += ElementAt(i); else w = ElementAt(i); if (w > wyn) wyn = w; } return wyn; /*LL start = from; LL len = 1; LL sum = ElementAt(from); LL curStart = from; LL curLen = 1; LL curSum = ElementAt(from); for (LL i = from + 1; i <= to; i++) { if (ElementAt(i) >= curSum + ElementAt(i)) { curStart = i; curLen = 1; curSum = ElementAt(i); } else { curLen++; curSum += ElementAt(i); } if ((curSum > sum) || (curSum == sum && curLen < len) || (curSum == sum && curLen == len && curStart < start)) { start = curStart; len = curLen; sum = curSum; } } return sum;*/ } int main() { if (MyNodeId() == 0) { cout << max_podciag(1, Size()); } return 0; /* LL skok; LL result; skok = Size() / NumberOfNodes(); LL* from = 0x0; LL* to = 0x0; LL starting = MyNodeId() == 0 ? 1 : (MyNodeId() * (skok + 1) + 1); if (MyNodeId() == NumberOfNodes() - 1) //ostatni skok = Size() - (MyNodeId() * skok + 1); LL max_num = max(starting, starting + skok, from, to); //cout << "Start from: " << starting << " end: " << starting + skok << " Max sum: " << max_num << " From: " << *from << " To: " << *to; if (MyNodeId() > 0) { PutLL(0, max_num); PutLL(0, *from); PutLL(0, *to); Send(0); } else { result = max_num; LL poprzednie_from = *from, poprzednie_to = *to; for (int i = 1; i < NumberOfNodes(); ++i) { int instancja = Receive(i); LL max_instancji = GetLL(instancja); LL from_instacji = GetLL(instancja); LL to_instacji = GetLL(instancja); if (poprzednie_to + 1 == from_instacji) //takie same ko�ce, sklejamy result += max_instancji; else if (max_instancji >= result) result = max_instancji; poprzednie_from = from_instacji; poprzednie_to = to_instacji; } cout << result; } return 0;*/ } |
English