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. Windows命令-系统木马取样

    1.前言 工作中偶尔会遇到去现场提取木马样本回公司分析的情况.如果是生产环境下,不方便安装各类抓包.安全软件时.能用系统自带的命令去定位出木马程序相关的信息是最理想不过的状态. 2.Windows常用 ...

  2. linux下的usb转串口的使用(修改)【转】

    环境:Ubuntu 10.10 Server minicom是linux下串口通信的软件,它的使用完全依靠键盘的操作,虽然没有“超级终端”那么易用,但是使用习惯之后读者将会体会到它的高效与便利,下面将 ...

  3. elasticsearch安装kibana插件

    1.下载 2.解压将解压后的文件放到D:\DevTools\kibana-4.6.0-windows-x86路径下 3.修改配置文件D:\DevTools\kibana-4.6.0-windows-x ...

  4. 初始ASP.NET数据控件【续 ListView】

    ListView控件   ListView控件可以用来显示数据,它还提供编辑,删除,插入,分页与排序等功能.ListView是GridView与DataList的融合体,它具有GridView控件编辑 ...

  5. Android工程方法数超过65535的解决办法

    Error:Execution failed for task ':ttt:transformClassesWithDexForDebug'.com.android.build.api.transfo ...

  6. 启动tomcat的时候爆出如下错误

    The JRE_HOME environment variable is not defined correctly This environment 解决办法: https://blog.csdn. ...

  7. Java编程的逻辑 (45) - 神奇的堆

    本系列文章经补充和完善,已修订整理成书<Java编程的逻辑>,由机械工业出版社华章分社出版,于2018年1月上市热销,读者好评如潮!各大网店和书店有售,欢迎购买,京东自营链接:http:/ ...

  8. GetNumber的实现(Python & Java & Golang)

    TCO2014的编程赢取门票的题目,大致是从一个数组(大小为K),可以选取1-K个数,必须保证这n个数是从1-n,返回所有的选取方法个数. 思路:首先是得到从1开始连续的数,保存每个数的个数.然后通过 ...

  9. THUSC 2018 酱油记

    THUSC 2018 酱油记 游记分类:游记 Day \((-inf,-2]\) 自CTSC和APIO挂烂以后,仍然在停课集训,不过好像这两波考试让我的RP涨了一大波,因此模拟赛大多都考的不错,虽然经 ...

  10. SSL证书链说明

    SSL证书链说明 1. SSL证书链定义 证书颁发机构(CA)共分为两种类型:根CA和中间CA.为了使SSL证书被信任,该证书必须由设备所连接的可信存储库CA颁发. 如果该证书不是由受信任CA,该链接 ...