bzoj 1083 2241
parent
77b0affb97
commit
dc5bc456a5
@ -0,0 +1,24 @@
|
||||
#include <cstdio>
|
||||
#include <algorithm>
|
||||
struct edge
|
||||
{
|
||||
int u, v, c;
|
||||
bool operator<(const edge &rhs) const { return c < rhs.c; }
|
||||
}E[900010];
|
||||
int n, m, cnt, ans, fa[310];
|
||||
int Find(int x) { return fa[x] == x ? x : fa[x] = Find(fa[x]); }
|
||||
int main()
|
||||
{
|
||||
for (int i = 0; i < 310; i++) fa[i] = i;
|
||||
scanf("%d%d", &n, &m);
|
||||
for (int i = 0; i < m; i++)
|
||||
scanf("%d%d%d", &E[i].u, &E[i].v, &E[i].c);
|
||||
std::sort(E, E + m);
|
||||
for (int i = 0, a, b; i < m && cnt < n - 1; i++)
|
||||
{
|
||||
a = Find(E[i].u), b = Find(E[i].v);
|
||||
if (a != b) fa[a] = b, cnt++, ans = E[i].c;
|
||||
}
|
||||
printf("%d %d", cnt, ans);
|
||||
return 0;
|
||||
}
|
||||
@ -0,0 +1,41 @@
|
||||
#include <cstdio>
|
||||
#include <cctype>
|
||||
#include <cstring>
|
||||
inline void readInt(int &x)
|
||||
{
|
||||
int ch = x = 0;
|
||||
while (!isdigit(ch = getchar()));
|
||||
for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
|
||||
}
|
||||
int m, n, a[105][105], t[105][105], sum, ans = 0x3f3f3f3f;
|
||||
void calc(int x, int y)
|
||||
{
|
||||
memcpy(t, a, sizeof(a));
|
||||
for (int i = 0; i < m; i++)
|
||||
for (int j = 0; j < n; j++)
|
||||
if (t[i][j])
|
||||
{
|
||||
int d = t[i][j];
|
||||
if (i + x > m || j + y > n) return;
|
||||
else for (int k = i; k < i + x; k++)
|
||||
for (int l = j; l < j + y; l++)
|
||||
{
|
||||
t[k][l] -= d;
|
||||
if (t[k][l] < 0) return;
|
||||
}
|
||||
}
|
||||
ans = sum / (x * y);
|
||||
}
|
||||
int main()
|
||||
{
|
||||
readInt(m), readInt(n);
|
||||
for (int i = 0; i < m; i++)
|
||||
for (int j = 0; j < n; j++)
|
||||
readInt(a[i][j]), sum += a[i][j];
|
||||
for (int i = m; i; i--)
|
||||
for (int j = n; j; j--)
|
||||
if (sum % (i * j) == 0 && sum / (i * j) < ans)
|
||||
calc(i, j);
|
||||
printf("%d", ans);
|
||||
return 0;
|
||||
}
|
||||
Loading…
Reference in new issue