为啥我这个程序在Dev C++ 上输出的不对,但在评测机上过了
查看原帖
为啥我这个程序在Dev C++ 上输出的不对,但在评测机上过了
822581
Blue_young楼主2023/7/23 10:18
#include<bits/stdc++.h>
#define int long long
using namespace std;
struct fs {
	unsigned int cnt2, cnt3, cnt5;
	long double fz;
	fs operator +(const fs x) {
		fs tmp = (fs) {
			max(cnt2, x.cnt2), max(cnt3, x.cnt3), max(cnt5, x.cnt5), 0
		};
		long double tmp1 = fz * pow(2, tmp.cnt2 - cnt2) * pow(3, tmp.cnt3 - cnt3) * pow(5, tmp.cnt5 - cnt5);
		long double tmp2 = x.fz * pow(2, tmp.cnt2 - x.cnt2) * pow(3, tmp.cnt3 - x.cnt3) * pow(5, tmp.cnt5 - x.cnt5);
		tmp1 += tmp2;
		while (round(tmp1 / 2) * 2 == tmp1 && tmp.cnt2 > 0)--tmp.cnt2, tmp1 /= 2;
		while (round(tmp1 / 3) * 3 == tmp1 && tmp.cnt3 > 0)--tmp.cnt3, tmp1 /= 3;
		while (round(tmp1 / 5) * 5 == tmp1 && tmp.cnt5 > 0)--tmp.cnt5, tmp1 /= 5;
		tmp.fz = tmp1;
		return tmp;
	}
} ans[100001];
int n, m, d[100001], a[100001][11], in[100001], vis[100001];
void dfs(int i) {
	vis[i] = 1;
	if (--in[i] <= 0) {
		if (d[i]) {
			fs tmp = ans[i];
			if (d[i] == 2)tmp.cnt2 += 1;
			if (d[i] == 3)tmp.cnt3 += 1;
			if (d[i] == 4)tmp.cnt2 += 2;
			if (d[i] == 5)tmp.cnt5 += 1;
			for (int j = 1; j <= d[i]; j++)ans[a[i][j]] = ans[a[i][j]] + tmp, dfs(a[i][j]);
		}
	}
}
signed main() {
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &d[i]);
		for (int j = 1; j <= d[i]; j++)scanf("%d", &a[i][j]), ++in[a[i][j]];
	}
	for (int i = 1; i <= m; i++)ans[i].fz = 1;
	for (int i = 1; i <= n; i++)if (in[i] == 0 && vis[i] == 0)dfs(i);
	for (int i = 1; i <= n; i++) {
		if (d[i] == 0) {
			printf("%.0Lf %.0Lf\n", ans[i].fz, ((long double)pow(2, ans[i].cnt2))*pow(3, ans[i].cnt3)*pow(5, ans[i].cnt5));
		}
	}
	return 0;
}
2023/7/23 10:18
加载中...