bzoj 1816 2429 2563 3098 (抄题解真的好爽啊但是感觉好堕落啊)

pull/1/head
雷宇辰 9 years ago
parent af5129d4ed
commit 2f9c79ce75

@ -0,0 +1,22 @@
//抄的题解谁告诉我这个check到底是什么意思
#include <cstdio>
int n, m, a[51];
bool check(int x)
{
int cnt = m < x ? m : x;
for (int i = 0; i < n; i++) if (a[i] < x)
{
cnt -= x - a[i];
if (cnt < 0) return false;
}
return true;
}
int main()
{
scanf("%d%d", &n, &m);
for (int i = 0; i < n; i++) scanf("%d", a + i);
int l = 0, r = 0x3f3f3f3f, mid;
while (l < r) check(mid = (l + r) >> 1) ? l = mid + 1 : r = mid;
printf("%d", l - 1);
return 0;
}

@ -0,0 +1,38 @@
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
using namespace std;
int fa[1010], X[1010], Y[1010], monkeys[510], m, n, ecnt, ans1;
double ans2;
int Find(int x) { return fa[x] == -1 ? x : fa[x] = Find(fa[x]); }
struct edge
{
int u, v;
double l;
bool operator<(const edge &rhs) const { return l < rhs.l; }
} edges[1000010];
int main()
{
memset(fa, -1, sizeof(fa));
scanf("%d", &m);
for (int i = 0; i < m; i++) scanf("%d", monkeys + i);
sort(monkeys, monkeys + m);
scanf("%d", &n);
for (int i = 1; i <= n; i++)
scanf("%d%d", X + i, Y + i);
for (int i = 1; i <= n; i++)
for (int j = 1; j < i; j++, ecnt++)
edges[ecnt].u = i, edges[ecnt].v = j, edges[ecnt].l =
sqrt((X[i] - X[j]) * (X[i] - X[j]) + (Y[i] - Y[j]) * (Y[i] - Y[j]));
sort(edges, edges + ecnt);
for (int i = 0, fx, fy; i < ecnt; i++)
if ((fx = Find(edges[i].u)) != (fy = Find(edges[i].v)))
{
fa[fx] = fy;
ans1++, ans2 = edges[i].l;
if (ans1 == n - 1) break;
}
printf("%d", int(monkeys + m - lower_bound(monkeys, monkeys + m, ans2)));
return 0;
}

@ -0,0 +1,24 @@
#include <cstdio>
#include <algorithm>
int a[10010];
int main()
{
int n, m, ans = 0;
scanf("%d%d", &n, &m);
for (int i = 1, x; i <= n; i++)
{
scanf("%d", &x);
ans -= x;
a[i] = x << 1;
}
for (int i = 1, x, y, z; i <= m; i++)
{
scanf("%d%d%d", &x, &y, &z);
ans -= z, a[x] += z, a[y] += z;
}
std::sort(a + 1, a + n + 1);
for (int i = 2; i <= n; i += 2)
ans += a[i];
printf("%d", ans);
return 0;
}

@ -0,0 +1,8 @@
#include <cstdio>
#include <cstdlib>
int main()
{
printf("100000 %d\n", ((rand() << 16) | rand()) % 100000 + 1);
for (int i = 0; i < 100000; i++) putchar(rand() % 26 + 'a');
return 0;
}
Loading…
Cancel
Save