Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
gzshawnliang committed Jul 14, 2019
1 parent 0f94eba commit e8735a7
Show file tree
Hide file tree
Showing 7 changed files with 199 additions and 20 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 = "almostShortestPath_UVA12144"; //*
const string CPPfile = "copyingBooks_UVA714"; //*
//***************************************

ifstream fin(CPPfile + ".cpp");
Expand Down
21 changes: 2 additions & 19 deletions myCpps/aGroupingProblem_UVA11026.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,10 @@ int main()
{
while (true)
{
int n = 0, m = 0; fin >> n >> m;
long long n = 0, m = 0; fin >> n >> m;
if (n + m == 0) break;

long long sum = 0, ans = -1;
vector<long long> a(n, 0), dp(n + 1, 0);

for (int i = 0; i <= n - 1; ++i)
{
fin >> a[i];

sum += (a[i] * a[i]);
dp[1] += a[i];
}

ans = max(ans, dp[1] % m);
for (int k = 2; k <= n; ++k)
{


ans = max(ans, dp[k] % m);
}

}

return 0;
Expand Down
7 changes: 7 additions & 0 deletions myCpps/aGroupingProblem_UVA11026.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
4 10
1 2 3 4
4 100
1 2 3 4
4 6
1 2 3 4
0 0
90 changes: 90 additions & 0 deletions myCpps/copyingBooks_UVA714.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#include <bits/stdc++.h>

using namespace std;

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

int main()
{
long long testCase; fin >> testCase;
for (long long t = 1; t <= testCase; ++t)
{
long long m, k; fin >> m >> k;

long long l = 0, r = 0;
vector<long long> a(m);
for (long long i = 0; i <= m - 1; ++i)
{
fin >> a[i];

r += a[i];
}

set<long long> s;
while (l <= r)
{
long long mid = (l + r) / 2,
kc = k, i = m - 1,
now = 0;
s.clear();

while (kc >= 1)
{
if (kc == 1)
{
while (i >= 0)
{
now += a[i];
--i;
}
break;
}
else if (i < kc - 1)
{
now = 0;
s.insert(i + 1);
--kc;
}
else if (now + a[i] > mid)
{
now = 0;
s.insert(i + 1);
--kc;
}
else
{
now += a[i];
--i;
}
}

if (now <= mid)
{
if (r == mid) break;
r = mid;
}
else
{
l = mid + 1;
}
}

vector<long long> fence_bool(m, 0);
for (auto it = s.begin(); it != s.end(); ++it)
{
long long pos = *it;
fence_bool[pos] = 1;
}

for (long long i = 0; i <= m - 1; ++i)
{
if (fence_bool[i] == 1) fout << " /";
if (i > 0) fout << ' ';
fout << a[i];
}
fout << '\n';
}

return 0;
}
5 changes: 5 additions & 0 deletions myCpps/copyingBooks_UVA714.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
2
9 3
100 200 300 400 500 600 700 800 900
5 4
100 100 100 100 100
2 changes: 2 additions & 0 deletions myCpps/copyingBooks_UVA714.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
100 200 300 400 500 / 600 700 / 800 900
100 / 100 / 100 / 100 100
92 changes: 92 additions & 0 deletions myCpps/copyingBooks_UVA714OJ.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#include <bits/stdc++.h>

using namespace std;


int main()
{
ios_base::sync_with_stdio(false);
std::cin.tie(NULL);
long long testCase; cin >> testCase;
for (long long t = 1; t <= testCase; ++t)
{
long long m, k; cin >> m >> k;

long long l = 0, r = 0;
vector<long long> a(m);
for (long long i = 0; i <= m - 1; ++i)
{
cin >> a[i];

r += a[i];
}

set<long long> s;
while (l <= r)
{
long long mid = (l + r) / 2,
kc = k, i = m - 1,
now = 0;
s.clear();

while (kc >= 1)
{
if (kc == 1)
{
while (i >= 0)
{
now += a[i];
--i;
}
break;
}
else if (i < kc - 1)
{
now = 0;
s.insert(i + 1);
--kc;
}
else if (now + a[i] > mid)
{
now = 0;
s.insert(i + 1);
--kc;
}
else
{
now += a[i];
--i;
}
}

if (now <= mid)
{
if (r == mid) break;
r = mid;
}
else
{
l = mid + 1;
}
}

vector<long long> fence_bool(m, 0);
for (auto it = s.begin(); it != s.end(); ++it)
{
long long pos = *it;
fence_bool[pos] = 1;
}

for (long long i = 0; i <= m - 1; ++i)
{
if (fence_bool[i] == 1) cout << " /";
if (i > 0) cout << ' ';
cout << a[i];
}
cout << '\n';
}

cout.flush();
return 0;
}

0 comments on commit e8735a7

Please sign in to comment.