bzoj 1045 1050 1214 2818 3293 3816
parent
536417f684
commit
bc49c51b9a
@ -0,0 +1,32 @@
|
|||||||
|
#include <cstdio>
|
||||||
|
#include <cctype>
|
||||||
|
#include <cstring>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <numeric>
|
||||||
|
typedef long long int64;
|
||||||
|
template <typename T> inline void readInt(T &x)
|
||||||
|
{
|
||||||
|
int ch = x = 0;
|
||||||
|
while (!isdigit(ch = getchar()));
|
||||||
|
for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
|
||||||
|
}
|
||||||
|
int64 *A, *C;
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
int n;
|
||||||
|
readInt(n);
|
||||||
|
A = new int64[n + 10];
|
||||||
|
C = new int64[n + 10];
|
||||||
|
memset(A, 0, sizeof(int64)*(n + 10));
|
||||||
|
memset(C, 0, sizeof(int64)*(n + 10));
|
||||||
|
for (int i = 0; i < n; i++) readInt(A[i]);
|
||||||
|
int64 tmp = std::accumulate(A, A + n, 0ll) / n;
|
||||||
|
for (int i = 1; i < n; i++)
|
||||||
|
C[i] = C[i - 1] + tmp - A[i];
|
||||||
|
std::nth_element(C, C + (n >> 1), C + n);
|
||||||
|
tmp = 0;
|
||||||
|
for (int i = 0; i < n; i++)
|
||||||
|
tmp += std::abs(C[i] - C[n >> 1]);
|
||||||
|
printf("%lld", tmp);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@ -0,0 +1,46 @@
|
|||||||
|
#include <cstdio>
|
||||||
|
#include <cstring>
|
||||||
|
#include <algorithm>
|
||||||
|
struct edge
|
||||||
|
{
|
||||||
|
int from, to, len;
|
||||||
|
bool operator<(const edge &rhs) const { return len < rhs.len; };
|
||||||
|
}edges[5010];
|
||||||
|
int fa[510];
|
||||||
|
int Find(int x) { return fa[x] == -1 ? x : fa[x] = Find(fa[x]); }
|
||||||
|
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
|
||||||
|
int n, m, s, t, ans1, ans2, flag;
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
scanf("%d%d", &n, &m);
|
||||||
|
for (int i = 0; i < m; i++) scanf("%d%d%d", &edges[i].from, &edges[i].to, &edges[i].len);
|
||||||
|
std::sort(edges, edges + m);
|
||||||
|
scanf("%d%d", &s, &t);
|
||||||
|
ans1 = edges[m - 1].len, ans2 = edges[0].len;
|
||||||
|
for (int i = 0, mn, mx; i < m; i++)
|
||||||
|
{
|
||||||
|
memset(fa, -1, sizeof(fa));
|
||||||
|
mn = edges[i].len;
|
||||||
|
for (int j = i, fx, fy; j < m; j++)
|
||||||
|
{
|
||||||
|
mx = edges[j].len;
|
||||||
|
fx = Find(edges[j].from), fy = Find(edges[j].to);
|
||||||
|
if (fx != fy) fa[fx] = fy;
|
||||||
|
if (Find(s) == Find(t))
|
||||||
|
{
|
||||||
|
if (ans1 * mn > ans2 * mx) ans1 = mx, ans2 = mn;
|
||||||
|
flag = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!flag) printf("IMPOSSIBLE");
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int k = gcd(ans1, ans2);
|
||||||
|
ans1 /= k, ans2 /= k;
|
||||||
|
if (ans2 == 1) printf("%d", ans1);
|
||||||
|
else printf("%d/%d", ans1, ans2);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@ -0,0 +1 @@
|
|||||||
|
int main() {}
|
||||||
@ -0,0 +1,29 @@
|
|||||||
|
#include <cstdio>
|
||||||
|
typedef long long int64;
|
||||||
|
const int maxn = 10000010;
|
||||||
|
int n, phi[maxn], prime[700010], pcnt;
|
||||||
|
int64 sum[maxn];
|
||||||
|
bool notPrime[maxn];
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
scanf("%d", &n);
|
||||||
|
phi[1] = 1;
|
||||||
|
for (int i = 2; i <= n; i++) if (!phi[i])
|
||||||
|
for (int j = i; j <= n; j += i)
|
||||||
|
{
|
||||||
|
if (!phi[j]) phi[j] = j;
|
||||||
|
phi[j] = phi[j] / i * (i - 1);
|
||||||
|
}
|
||||||
|
for (int64 i = 2; i <= n; i++) if (!notPrime[i])
|
||||||
|
for (int64 j = i * i; j <= n; j += i)
|
||||||
|
notPrime[j] = true;
|
||||||
|
for (int i = 2; i <= n; i++)
|
||||||
|
if (!notPrime[i])
|
||||||
|
prime[pcnt++] = i;
|
||||||
|
for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + phi[i];
|
||||||
|
int64 ans = 0;
|
||||||
|
for (int i = 0; i < pcnt; i++)
|
||||||
|
ans += (sum[n / prime[i]] << 1) - 1;
|
||||||
|
printf("%lld", ans);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@ -0,0 +1,32 @@
|
|||||||
|
#include <cstdio>
|
||||||
|
#include <cctype>
|
||||||
|
#include <cstring>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <numeric>
|
||||||
|
typedef long long int64;
|
||||||
|
template <typename T> inline void readInt(T &x)
|
||||||
|
{
|
||||||
|
int ch = x = 0;
|
||||||
|
while (!isdigit(ch = getchar()));
|
||||||
|
for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
|
||||||
|
}
|
||||||
|
int64 *A, *C;
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
int n;
|
||||||
|
readInt(n);
|
||||||
|
A = new int64[n + 10];
|
||||||
|
C = new int64[n + 10];
|
||||||
|
memset(A, 0, sizeof(int64)*(n + 10));
|
||||||
|
memset(C, 0, sizeof(int64)*(n + 10));
|
||||||
|
for (int i = 0; i < n; i++) readInt(A[i]);
|
||||||
|
int64 tmp = std::accumulate(A, A + n, 0ll) / n;
|
||||||
|
for (int i = 1; i < n; i++)
|
||||||
|
C[i] = C[i - 1] + tmp - A[i];
|
||||||
|
std::nth_element(C, C + (n >> 1), C + n);
|
||||||
|
tmp = 0;
|
||||||
|
for (int i = 0; i < n; i++)
|
||||||
|
tmp += std::abs(C[i] - C[n >> 1]);
|
||||||
|
printf("%lld", tmp);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@ -0,0 +1 @@
|
|||||||
|
int main() {}
|
||||||
Loading…
Reference in new issue