Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
gzshawnliang committed Jan 29, 2019
1 parent a6b7eaf commit 7223f00
Show file tree
Hide file tree
Showing 9 changed files with 27,125 additions and 1 deletion.
2 changes: 1 addition & 1 deletion myCpps/!-OJcreater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
using namespace std;

//***************************************
const string CPPfile = "pingPong_UVA1428"; //*
const string CPPfile = "JillRidesAgain_UVA507"; //*
//***************************************

ifstream fin(CPPfile + ".cpp");
Expand Down
80 changes: 80 additions & 0 deletions myCpps/JillRidesAgain_UVA507.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#include <bits/stdc++.h>

using namespace std;

ifstream fin("JillRidesAgain_UVA507.in");
ofstream fout("JillRidesAgain_UVA507.out");

struct solution
{
int l;
int r;
int v;
};

int main()
{
int testCase; fin >> testCase;
for (int r = 1; r <= testCase; ++r)
{
int s; fin >> s;
vector<int> a(s, 0);
for (int i = 1; i <= s - 1; ++i)
{
fin >> a[i];
}

solution ans{1, 2, a[1]}, _null{0, 0, 0};

vector<solution> dp(s, _null);
dp[1] = ans;

for (int i = 2; i <= s - 1; ++i)
{
dp[i].r = i + 1;

if (dp[i - 1].v >= 0)
{
dp[i].v = dp[i - 1].v + a[i];

dp[i].l = dp[i - 1].l;
}
else
{
dp[i].v = a[i];

dp[i].l = i;
}

if (dp[i].v > ans.v)
{
ans = dp[i];
}
else if (dp[i].v == ans.v)
{
if (dp[i].r - dp[i].l > ans.r - ans.l)
{
ans = dp[i];
}
else if (dp[i].r - dp[i].l == ans.r - ans.l)
{
if (dp[i].l < ans.l)
{
ans = dp[i];
}
}
}
}

if (ans.v < 0)
{
fout << "Route " << r << " has no nice parts\n";
}
else
{
fout << "The nicest part of route " << r << " is between stops " << ans.l << " and " << ans.r << '\n';
}
}

return 0;
}
Loading

0 comments on commit 7223f00

Please sign in to comment.