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. 进程ID[PID(Process ID)]与端口号[(Port ID)]的联系

    1.首先声明一点:PID不是端口(port id),而是Process ID进程号的意思. 2.那么,什么是进程号? 采集网友的意见就是: 进程号,是系统分配给么一个进程的唯一标识符.PID就是各进程 ...

  2. 以python代码解释fork系统调用

    import os print('Process (%s) start...' % os.getpid()) # Only works on Unix/Linux/Mac: pid = os.fork ...

  3. android getWidth()和getMeasuredWidth()方法的区别

    getWidth() Return the width of the your view. Returns The width of your view, in pixels. 源代码: public ...

  4. 洛谷 P3749: LOJ 2146: [SHOI2017]寿司餐厅

    题目传送门:LOJ #2146. 题意简述: 有 \(n\) 种寿司,第 \(i\) 种寿司的类型为 \(a_i\). 如果你吃了第 \(i\) 种到第 \(j\) 种寿司,你会得到 \(d_{i,j ...

  5. Linux 内核中断内幕【转】

    转自:http://www.ibm.com/developerworks/cn/linux/l-cn-linuxkernelint/ 本文对中断系统进行了全面的分析与探讨,主要包括中断控制器.中断分类 ...

  6. Memcached实战之复制----基于repcached的主从【转】

    由于 Memcached 自己没有防止单点的措施,因为为了保障 Memcached 服务的高可用,我们需要借助外部的工具来实现高可用的功能.本文引入 Repcached 这个工具,通过使用该工具我们可 ...

  7. PHP取整函数之ceil,floor,round,intval的区别

    我们经常用到的PHP取整函数,主要是:ceil,floor,round,intval. ceil -- 进一法取整 说明 float ceil ( float value ) 返回不小于 value ...

  8. 一个洛谷Material化的Stylish美化主题

    Luogu Argon Design 新主题 Luogu Argon Design 目前已经取代了 Luogu Material,但这并不代表 Luogu Material 会停止更新,在 Luogu ...

  9. ***解决UEditor编辑器无法插入第三方视频地址

    转:http://blog.csdn.net/qq_16241043/article/details/53894847 xssFilter导致插入视频异常,编辑器在切换源码的过程中过滤掉img的_ur ...

  10. Storm集群启动流程分析

    Storm集群启动流程分析 程序员 1.客户端运行storm nimbus时,会调用storm的python脚本,该脚本中为每个命令编写了一个方法,每个方法都可以生成一条相应的Java命令. 命令格式 ...