BZOJ2419 电阻

<div class="post_brief"><p> 记得这是高一的时候ty同学和我说的东西了。然后现在才解决,可以打败上帝造题的七分钟,荣登解决时间最长的题目了。</p>   其实也就是一个高斯消元,用电势来列方程。不过高斯消元写得不熟,平时有空都写ds的题去了。以后不能再这样了。   用自己的代码高亮脚本了,虽然还不完善不过还是很开心的。   #include <cstdio> #include <cstring> #include <cmath> #include <cstdlib> #include <algorithm> using namespace std; const int maxn = 109; const double inf = 1e100; const double eps = 1e-8; double x[maxn], a[maxn][maxn], b[maxn][maxn]; int n, m, perm[maxn]; int main() { #ifndef ONLINE_JUDGE freopen(“in.txt”, “r”, stdin); #endif srand(19970911); while (scanf("%d%d", &amp;n, &amp;m) != EOF) { for (int i = 1; i &lt;= n; ++ i) perm[i] = i; if (n &gt; 2) random_shuffle(perm + 2, perm + n); for (int i = 1; i &lt;= n; ++ i) for (int j = 1; j &lt;= n; ++ j) if (i == j) a[i][j] = 0; else a[i][j] = inf; while (m --) { int u, v; double p; scanf("%d%d%lf", &amp;u, &amp;v, &amp;p); u = perm[u]; v = perm[v]; if (u == v) continue; a[u][v] = 1....

January 25, 2015 · 2 min · laekov