A. Simulation
#include <bits/stdc++.h>using namespace std; #define LL long long#define INF 0x3f3f3f3f#define maxn 10char s[4] [Maxn];int Len[4];int Main () {int T1, T2; int Min = INF, Max =-inf; for (int i = 0; i < 4; i++) {scanf ("%s", S[i]); Len[i] = strlen (S[i])-2; cout<<len[i]<<endl; if (Max < len[i]) {max = len[i]; T1 = i; } if (min > Len[i]) {min = len[i]; t2 = i; }} int t = 0; int ans; int i; for (i = 0; i < 4; i++) {if (i! = T1 && Max < 2 * Len[i]) {break; }} if (i = = 4) {t++; ans = T1; } for (i = 0; i < 4; i++) {if (i! = T2 && 2 * Min > Len[i]) break; } if (i = = 4) {t++; ans = T2; } if (t = = 2 | | t = = 0) printf ("c\n"); else printf ("%c\n", ' A ' + ans); return 0;} /*a._b.__c.____d.________*/
B. Reasoning
#include <bits/stdc++.h>using namespace Std;int lowbit (int x) { return x & (-X);} int N, m;int a[100005];int cnt = 0;int Main () { cin>>n>>m; for (int i = m; I >= 1; i--) { if (lowbit (i) <= N) { N-= lowbit (i); a[cnt++] = i; } if (n = = 0) break; } if (n! = 0) printf (" -1\n"); else { cout<<cnt<<endl; for (int i = 0; i < cnt; i++) { i = = cnt-1? printf ("%d\n", A[i]): printf ("%d", A[i]);} } return 0;}
C. Reasoning
#include <bits/stdc++.h>using namespace std; #define LL long long#define INF 0x3f3f3f3f#define maxn 100000 + 10int v[ Maxn];int N, m;int Main () { cin>>n>>m; for (int i = 1; I <= n; i++) scanf ("%d", V + i); A long long ans = 0; for (int i = 0; i < m; i++) { int uu, VV; scanf ("%d%d", &uu, &VV); Ans + = min (V[uu], v[vv]); } printf ("%i64d\n", ans); return 0;}
D. And look up the set
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm>using namespace STD; #define N 100000 + 10struct edge{int u, V, W;} E[n];int N, M;int w[n];int f[n], cnt[n];d ouble ans = 0;int cmp (Edge A, Edge b) {return A.W > b.w;} void Mekeset () {for (int i = 1; I <= n; i++) {f[i] = i; Cnt[i] = 1; }}int find (int x) {return x = = F[x]? x:f[x] = Find (F[x]);} int Union (int i, int x, int y) {int xx = Find (x); int yy = Find (y); if (xx! = yy) {ans + = (double) E[I].W * CNT[XX] * CNT[YY]; CNT[XX] + = Cnt[yy]; F[YY] = XX; }}int Main () {scanf ("%d%d", &n, &m); for (int i = 1; I <= n; i++) {scanf ("%d", w + i); } for (int i = 0; i < m; i++) {scanf ("%d%d", &e[i].u, &E[I].V); E[I].W = min (w[e[i].u], w[e[i].v]); } sort (E, E + M, CMP); Mekeset (); for (int i = 0; i < m; i++) {Union (i, e[i].u, E[I].V); } ans = ans * 2/((double) n * (n-1)); printf ("%.6lf\n", ans); return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Codeforces div2 A B C D