Pagini recente » Istoria paginii runda/gluma_de_1_aprilie/clasament | Cod sursa (job #2683162) | Cod sursa (job #468967) | Cod sursa (job #795692) | Cod sursa (job #2610378)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("aliens.in");
ofstream fout("aliens.out");
const int l3 = 18 * 50 + 30, l5 = 12 * 50 + 30;
short int dp[2][l3 + l3 + 5][l5 + l5 + 5], inf = -30000, p, q, u, v;
double best = -1;
int main()
{
for (int i = 0; i <= l3 + l3; ++i)
{
for (int j = 0; j <= l5 + l5; ++j)
{
dp[0][i][j] = inf;
}
}
dp[0][l3][l5] = 0;
int n;
fin >> n;
for (int i = 1; i <= n; ++i)
{
int x, y;
short int p2 = 0, p3 = 0, p5 = 0;
fin >> x >> y;
while (x % 2 == 0) x /= 2, ++p2;
while (x % 3 == 0) x /= 3, ++p3;
while (x % 5 == 0) x /= 5, ++p5;
while (y % 2 == 0) y /= 2, --p2;
while (y % 3 == 0) y /= 3, --p3;
while (y % 5 == 0) y /= 5, --p5;
if (p3 >= 0) p += p3;
else q += p3;
if (p5 >= 0) u += p5;
else v += p5;
for (int j = q; j <= p; ++j)
{
for (int k = u; k <= v; ++k)
{
dp[i % 2][j + l3][k + l3] = inf;
if (dp[1 - i % 2][j + l3][k + l3] > dp[i % 2][j + l3][k + l3])
{
dp[i % 2][j + l3][k + l3] = dp[1 - i % 2][j + l3][k + l3];
}
if (p2 + dp[1 - i % 2][j - p3 + l3][k - p5 + l5] > dp[i % 2][j + l3][k + l3])
{
dp[i % 2][j + l3][k + l3] = p2 + dp[1 - i % 2][j - p3 + l3][k - p5 + l5];
}
}
}
}
fin.close();
fout.close();
return 0;
}