Electric resistance

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 326    Accepted Submission(s): 156

Problem Description
Now give you a circuit who has n nodes (marked from 1 to n) , please tell abcdxyzk the equivalent resistance of the circuit between node 1 and node n. You may assume that the circuit is connected. The equivalent resistance of the circuit between 1 and n is that, if you only consider node 1 as positive pole and node n as cathode , all the circuit could be regard as one resistance . (It's important to analyse complicated circuit ) At most one resistance will between any two nodes.
 
Input
In the first line has one integer T indicates the number of test cases. (T <= 100)

Each test first line contain two number n m(1<n<=50,0<m<=2000), n is the number of nodes, m is the number of resistances.Then follow m lines ,each line contains three integers a b c, which means there is one resistance between node a and node b whose resistance is c. (1 <= a,b<= n, 1<=c<=10^4) You may assume that any two nodes are connected!

 
Output
for each test output one line, print "Case #idx: " first where idx is the case number start from 1, the the equivalent resistance of the circuit between 1 and n. Please output the answer for 2 digital after the decimal point .
 
Sample Input
1
4 5
1 2 1
2 4 4
1 3 8
3 4 19
2 3 12
 
Sample Output
Case #1: 4.21
 
Author
abcdxyzk
 
Source
 

高斯消元解方程组。

主要是方程的建立。

我建方程使用了n个未知数,表示n个点的电势。

需要列n个方程。

就根据n个点,流入电流等于流出电流,或者说每个点电流之和(假如流入为正,流出为负,反之也可)

这样可以列出n个方程,根据n个点电流和为0.

而且可以假设1这个点流入电流为-1, 这样设点电势为0,那么可以知道n这个点的电势就等于等效电阻了、。

流入肯定等于流出的,上面列的方程组中第n个的是多余的,可以去掉,替换成1点电压为0.

这样方程组正确建立。

对于u  ---->  v  电阻为w.   可以知道u加一个电流  xv/w - xu/w.  而v加一个电流 xu/w - xv/w;

 /* ***********************************************
Author :kuangbin
Created Time :2013-11-17 23:18:47
File Name :E:\2013ACM\比赛练习\2013-11-17\EE.cpp
************************************************ */ #include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
const double eps = 1e-;
const int MAXN = ;
double a[MAXN][MAXN],x[MAXN];
int equ,var;
int Gauss()
{
int i,j,k,col,max_r;
for(k = ,col = ;k < equ && col < var;k++,col++)
{
max_r = k;
for(i = k+;i < equ;i++)
if(fabs(a[i][col]) > fabs(a[max_r][col]))
max_r = i;
if(fabs(a[max_r][col]) < eps)return ;
if(k != max_r)
{
for(j = col;j < var;j++)
swap(a[k][j],a[max_r][j]);
swap(x[k],x[max_r]);
}
x[k]/=a[k][col];
for(j = col+;j < var;j++)a[k][j]/=a[k][col];
a[k][col] = ;
for(int i = ;i < equ;i++)
if(i != k)
{
x[i] -= x[k]*a[i][k];
for(j = col+;j < var;j++)a[i][j] -= a[k][j]*a[i][col];
a[i][col] = ;
}
}
return ;
}
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int n,m;
int T;
int iCase = ;
scanf("%d",&T);
while(T--)
{
iCase++;
scanf("%d%d",&n,&m);
equ = var = n;
memset(a,,sizeof(a));
int u,v,w;
for(int i = ;i < m;i++)
{
scanf("%d%d%d",&u,&v,&w);
a[u-][v-] += 1.0/w;
a[u-][u-] += -1.0/w;
a[v-][u-] += 1.0/w;
a[v-][v-] += -1.0/w;
}
for(int i = ;i < n-;i++)
x[i] = ;
x[] = ;
for(int i = ;i < n;i++)
a[n-][i] = ;
x[n-] = ;
a[n-][] = ;
Gauss();
printf("Case #%d: %.2lf\n",iCase,x[n-]);
}
return ;
}

第一次写的时候用n+m个未知数做的,也可以A掉,但是有m个变量多余了。

HDU 3976 Electric resistance (高斯消元法)的更多相关文章

  1. [Gauss]HDOJ3976 Electric resistance

    题意: 一看图就明白了 要求的是1与n端点间的等效电阻 重点在于转化成考虑电流 根据KCL定理:在任一瞬间流出(流入)该节点的所有电流的代数和恒为零 U = IR 可以令1点的电势为零 那么n点的电势 ...

  2. [HDU3976]Electric resistance(电阻)(信竞&物竞)(高斯消元)

    题面 Problem Description Now give you a circuit who has n nodes (marked from 1 to n) , please tell abc ...

  3. UVALive - 3942 Remember the Word[树状数组]

    UVALive - 3942 Remember the Word A potentiometer, or potmeter for short, is an electronic device wit ...

  4. ACM第一阶段学习内容

    一.知识目录 字符串处理 ................................................................. 3 1.KMP 算法 .......... ...

  5. hdu 5833 Zhu and 772002 ccpc网络赛 高斯消元法

    传送门:hdu 5833 Zhu and 772002 题意:给n个数,每个数的素数因子不大于2000,让你从其中选则大于等于1个数相乘之后的结果为完全平方数 思路: 小于等于2000的素数一共也只有 ...

  6. hdu 5755 Gambler Bo (高斯消元法解同余方程组)

    http://acm.hdu.edu.cn/showproblem.php?pid=5755 题意: n*m矩阵,每个格有数字0/1/2 每选择一个格子,这个格子+2,4方向相邻格子+1 如何选择格子 ...

  7. HDU 4870 Rating 高斯消元法

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=4870 题意:用两个账号去參加一种比赛,初始状态下两个账号都是零分,每次比赛都用分数低的账号去比赛.有P的概 ...

  8. HDU 4418 高斯消元法求概率DP

    把两种状态化成2*n-2的一条线上的一种状态即可.很容易想到. 高斯列主元法,不知为什么WA.要上课了,不玩了...逃了一次课呢.. #include <iostream> #includ ...

  9. 转载:hdu 题目分类 (侵删)

    转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...

随机推荐

  1. [百度地图] 用于类似 DWZ UI 框架的 百度地图 功能封装类 [MultiZMap.js] 实例源码

    MultiZMap 功能说明 MultiZMap.js 本类方法功能大多使用 prototype 原型 实现,它是 ZMap 的多加载版本,主要用于类似 DWZ 这个 多标签的 UI 的框架: 包含的 ...

  2. svn使用笔记

    一.checkout:第一次下载trunk里面的代码到本地 二.commit:提交一些修改* out of date : 本地版本号 < 服务器版本号* 如果过期,就update,可能会出现co ...

  3. SQLSTATE[42000]

    SQLSTATE[42000]: Syntax error or access violation: 1140 Mixing of GROUP columns (MIN(),MAX(),COUNT() ...

  4. PyQT5 No module named ‘PyQt5.QtWebEngineWidgets’

    PyQT5查找不到模块QtWebEngineWidgets pip install pyqt5==5.10.1 或 安装64位的Pyhon解释器

  5. vue-cli 3.0 开启 Gzip 方法

    vue.config.js const path = require('path') const CompressionWebpackPlugin = require('compression-web ...

  6. Windows 8.1/10配置VS 2013 + MPI开发环境

    关于win上安装MPI开发环境,网上能搜到的教程貌似都很老,还需要在管理员账户开发,感觉很诡异,于是自己摸索了下,不需要管理员账户,总结如下. 1. 准备 VS 2013(VS 2010及以上都行) ...

  7. 在Jenkins中配置执行远程shell命令(转)

    用过Jenkins的都知道,在Build配置那里有1个Add buld step, 有这样两个选项: 1. Execute Windows batch command 2. Execute shell ...

  8. C# 各版本新特性

    C# 2.0 泛型(Generics) 泛型是CLR 2.0中引入的最重要的新特性,使得可以在类.方法中对使用的类型进行参数化. 例如,这里定义了一个泛型类: class MyCollection&l ...

  9. Java基础84 javaBean规范

    1.javaBean的概述 1.javaBeam(咖啡豆)是一种开发规范,也可以说是一种技术.  2.JavaBean就是一个普通java类,只要符合以下规定才能称作为javaBean:        ...

  10. java 通过异常处理错误

    java的基本理念是"结构不佳的代码不能够运行" 一.概念 发现错误的理想时机是编译阶段,然而,编译期间并不能找出所有的错误,余下的问题必须在运行时期解决. 二.基本异常 异常情形 ...