标签:acm codeforces
A. 模拟
#include <bits/stdc++.h> using namespace std; #define LL long long #define INF 0x3f3f3f3f #define maxn 100 + 10 char 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.________ */
#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; }
#include <bits/stdc++.h> using namespace std; #define LL long long #define INF 0x3f3f3f3f #define maxn 100000 + 10 int v[maxn]; int n, m; int main() { cin>>n>>m; for(int i = 1; i <= n ; i++) scanf("%d", v + i); 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; }
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; #define N 100000 + 10 struct Edge { int u, v, w; }e[N]; int n, m; int w[N]; int f[N], cnt[N]; double 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; }
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:acm codeforces
原文地址:http://blog.csdn.net/dojintian/article/details/47703527