Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

额,G++容易自带WA Buff,珍惜生命,交C++

Posted by yousiki at 2016-07-29 14:40:05 on Problem 1926
#include<bitset>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
const int N = 105;
int T, n, m, cnt[N];
bitset<N> G[N];
double init[N];
signed main(void) {
	for (scanf("%d", &T); T; T--, putchar('\n')) {
		scanf("%d%d",&n,&m); memset(cnt, 0, sizeof(cnt));
		for (int i = 1; i <= n; i++)scanf("%lf", init + i), G[i].reset(), G[i][i] = true;
		for (int i = 1, x, y; i <= m; i++)scanf("%d%d", &x, &y), G[x][y] = G[y][x] = true;
		for (int i = 1; i <= n; i++)cnt[i] = G[i].count() - 1;
		for (int k = 1; k <= n; k++)
			for (int i = 1; i <= n; i++)
				for (int j = 1; j <= n; j++)
					G[i][j] = G[i][j] | G[i][k] & G[k][j];
		for (int i = 1; i <= n; i++) {
			double ans = 0.0; int Cnt = 0;
			for (int j = 1; j <= n; j++)
				if (G[i][j])ans += init[j], Cnt += cnt[j];
			printf("%.3lf\n", Cnt ? ans*cnt[i] / (double)Cnt : ans);
		}
	}
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator