Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
gzshawnliang committed Aug 2, 2019
1 parent 3144f46 commit cb6d6a0
Show file tree
Hide file tree
Showing 8 changed files with 219 additions and 67 deletions.
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 = "unidirectionalTSP_UVA116"; //*
const string CPPfile = "NEW_maximumSum_UVA108"; //*
//***************************************

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

using namespace std;

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

const int minf = -128;

int main()
{
while (true)
{
int n = 0; fin >> n;
if (n == 0) break;

vector<vector<int>> a(n + 1, vector<int>(n + 1, minf));
for (int y = 1; y <= n; ++y)
{
for (int x = 1; x <= n; ++x)
{
fin >> a[y][x];
}
}

vector<vector<int>> dp(n + 1, vector<int>(n + 1, 0));
for (int x = 1; x <= n; ++x)
{
for (int y = 1; y <= n; ++y)
{
dp[x][y] = dp[x][y - 1] + a[y][x];
}
}

int ans = minf;
for (int y1 = 1; y1 <= n; ++y1)
{
for (int y2 = y1; y2 <= n; ++y2)
{
int last = 0;
for (int x = 1; x <= n; ++x)
{
int now = dp[x][y2] - dp[x][y1 - 1];

last = max(now, last + now);
ans = max(ans, last);
}
}
}

fout << ans << '\n';
}

return 0;
}
16 changes: 16 additions & 0 deletions myCpps/NEW_maximumSum_UVA108.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
4
-1 -2 -3 -4
-5 -6 -7 -8
-9 -10 -11 -12
-13 -14 -15 -16
5
1 -61 5126 612 6
41 6 7 2 -7
1 73 -62 678 1
7 -616136 61 -83 724
-151 6247 872 2517 8135
4
0 -2 -7 0
9 2 -6 2
-4 1 -4 1
-1 8 0 -2
3 changes: 3 additions & 0 deletions myCpps/NEW_maximumSum_UVA108.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-1
18589
15
57 changes: 57 additions & 0 deletions myCpps/NEW_maximumSum_UVA108OJ.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#include <bits/stdc++.h>

using namespace std;


const int minf = -128;

int main()
{
ios_base::sync_with_stdio(false);
std::cin.tie(NULL);
while (true)
{
int n = 0; cin >> n;
if (n == 0) break;

vector<vector<int>> a(n + 1, vector<int>(n + 1, minf));
for (int y = 1; y <= n; ++y)
{
for (int x = 1; x <= n; ++x)
{
cin >> a[y][x];
}
}

vector<vector<int>> dp(n + 1, vector<int>(n + 1, 0));
for (int x = 1; x <= n; ++x)
{
for (int y = 1; y <= n; ++y)
{
dp[x][y] = dp[x][y - 1] + a[y][x];
}
}

int ans = minf;
for (int y1 = 1; y1 <= n; ++y1)
{
for (int y2 = y1; y2 <= n; ++y2)
{
int last = 0;
for (int x = 1; x <= n; ++x)
{
int now = dp[x][y2] - dp[x][y1 - 1];

last = max(now, last + now);
ans = max(ans, last);
}
}
}

cout << ans << '\n';
}

cout.flush();
return 0;
}

66 changes: 0 additions & 66 deletions myCpps/maximumSum.cpp
Original file line number Diff line number Diff line change
@@ -1,66 +0,0 @@
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <climits>
#include <functional>
#include <iomanip>
#include <iostream>
#include <set>
#include <string>
#include <vector>

using namespace std;

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

int main()
{
while (true)
{
int n = - 1;
fin >> n;

if (n == -1)
{
break;
}

vector<vector<int>> a(n, vector<int>(n));
vector<vector<int>> dp(n, vector<int>(n + 1));
for (int y = 0; y <= n - 1; ++y)
{
int sum = 0;
dp[y][0] = 0;
for (int x = 0; x <= n - 1; ++x)
{
fin >> a[y][x];
sum += a[y][x];
dp[y][x + 1] = sum;
}
}

int maxSum = INT_MIN;
for (int y0 = 0; y0 <= n - 1; ++y0)
{
for (int x0 = 0; x0 <= n - 1; ++x0)
{
for (int x1 = x0 + 1; x1 <= n; ++x1)
{
int sum = 0;
for (int y1 = y0; y1 <= n - 1; ++y1)
{
sum += dp[y1][x1] - dp[y1][x0];
maxSum = max(maxSum, sum);
}
}
}
}

fout << maxSum << '\n';
}

return 0;
}
66 changes: 66 additions & 0 deletions myCpps/maximumSumB.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <climits>
#include <functional>
#include <iomanip>
#include <iostream>
#include <set>
#include <string>
#include <vector>

using namespace std;

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

int main()
{
while (true)
{
int n = - 1;
fin >> n;

if (n == -1)
{
break;
}

vector<vector<int>> a(n, vector<int>(n));
vector<vector<int>> dp(n, vector<int>(n + 1));
for (int y = 0; y <= n - 1; ++y)
{
int sum = 0;
dp[y][0] = 0;
for (int x = 0; x <= n - 1; ++x)
{
fin >> a[y][x];
sum += a[y][x];
dp[y][x + 1] = sum;
}
}

int maxSum = INT_MIN;
for (int y0 = 0; y0 <= n - 1; ++y0)
{
for (int x0 = 0; x0 <= n - 1; ++x0)
{
for (int x1 = x0 + 1; x1 <= n; ++x1)
{
int sum = 0;
for (int y1 = y0; y1 <= n - 1; ++y1)
{
sum += dp[y1][x1] - dp[y1][x0];
maxSum = max(maxSum, sum);
}
}
}
}

fout << maxSum << '\n';
}

return 0;
}
21 changes: 21 additions & 0 deletions other2/thomas/lineSwap.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include <bits/stdc++.h>

using namespace std;

//ifstream fin("lineSwap.in");
//ofstream fout("lineSwap.out");

class line
{
double y_start;
double y_end;
double x;
int flag;
};

int main()
{


return 0;
}

0 comments on commit cb6d6a0

Please sign in to comment.