[Gauss]HDOJ3976 Electric resistance
题意: 一看图就明白了 要求的是1与n端点间的等效电阻
重点在于转化成考虑电流
根据KCL定理:在任一瞬间流出(流入)该节点的所有电流的代数和恒为零
U = IR
可以令1点的电势为零 那么n点的电势就等于它的等效电阻
可以列出方程组 $\sum\limits \frac{U_j-U_i}{R_ij} + I = 0$
$U_0$ = 0;
double a[][]; // 增广矩阵
double x[]; // 解
int free_x[]; // 标记是否为自由未知量 void Gauss(int n, int m) // n个方程 m个未知数 即 n行m+1列
{
//转换为阶梯形式
int col=, k;
for(k=;k<n && col<m;k++, col++)
{//枚举行
int max_r=k;
for(int i=k+;i<n;i++)//找到第col列元素绝对值最大的那行与第k行交换
if(fabs(a[i][col])>fabs(a[max_r][col]))
max_r=i;
if(fabs(a[max_r][col])<eps)
return ;
if(max_r!=k)// 与第k行交换
{
for(int j=col;j<m;j++)
swap(a[k][j], a[max_r][j]);
swap(x[k], x[max_r]);
}
x[k]/=a[k][col];
for(int i=col+;i<m;i++)
a[k][i]/=a[k][col];
a[k][col]=;
for(int i=;i<m;i++)
if(i!=k)
{
x[i]-=x[k]*a[i][k];
for(int j=col+;j<m;j++)
a[i][j]-=a[k][j]*a[i][col];
a[i][col]=;
}
}
} void init()
{
memset(a, , sizeof(a));
memset(x, , sizeof(x));
} int main()
{
int T, ca=;
scanf("%d", &T);
while(T--)
{
int n, m;
scanf("%d%d", &n, &m);
init();
for(int i=;i<m;i++)
{
int X, Y, Z;
scanf("%d%d%d", &X, &Y, &Z);
X--, Y--;
a[X][Y]+=1.0/Z;
a[Y][X]+=1.0/Z;
a[X][X]-=1.0/Z;
a[Y][Y]-=1.0/Z;
}
printf("Case #%d: ", ca++);
fill(a[n-], a[n-]+n, );
a[n-][]=;
x[]=;
Gauss(n, n);
printf("%.2lf\n", x[n-]);
}
return ;
}
HDOJ 3976
[Gauss]HDOJ3976 Electric resistance的更多相关文章
- HDU 3976 Electric resistance (高斯消元法)
Electric resistance Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
- [HDU3976]Electric resistance(电阻)(信竞&物竞)(高斯消元)
题面 Problem Description Now give you a circuit who has n nodes (marked from 1 to n) , please tell abc ...
- UVALive - 3942 Remember the Word[树状数组]
UVALive - 3942 Remember the Word A potentiometer, or potmeter for short, is an electronic device wit ...
- poj 3532 Resistance
---恢复内容开始--- Resistance Time Limit: 1000MS Memory Limit: 131072K Total Submissions: 1289 Accepte ...
- OPEN CASCADE Gauss Least Square
OPEN CASCADE Gauss Least Square eryar@163.com Abstract. The least square can be used to solve a set ...
- OpenCASCADE Gauss Integration
OpenCASCADE Gauss Integration eryar@163.com Abstract. Numerical integration is the approximate compu ...
- The Non-Inverting Amplifier Output Resistance by Adrian S. Nastase [ Copied ]
Source Address: http://masteringelectronicsdesign.com/the-non-inverting-amplifier-output-resistance/ ...
- ural 1143. Electric Path
1143. Electric Path Time limit: 1.0 secondMemory limit: 64 MB Background At the team competition of ...
- C# 列主元素(Gauss)消去法 计算一元多次方程组
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
随机推荐
- ASP判断文件地址是否有效
<% Response.Write("<head><style><!--span{ font-size: 9pt }--></style> ...
- ASP中双引号单引号和&连接符使用技巧
ASP中双引号单引号和&连接符使用技巧 一.ASP中处在双引号中的可以是任意的字符.字符串,HTML代码 1.<%response.write ("I am here" ...
- android 权限总结
1.拨打电话要权限 2.sd目录存东西要权限
- Java实战之02Hibernate-03Session中的常用方法
九.Session中的常用方法 1.save方法 都是临时态————>持久态 2.persist方法 作用: 持久化临时态对象. 与save方法的区别: 开始了事务:persist和save没有 ...
- [leetcode]352. Data Stream as Disjoint Intervals
数据流合并成区间,每次新来一个数,表示成一个区间,然后在已经保存的区间中进行二分查找,最后结果有3种,插入头部,尾部,中间,插入头部,不管插入哪里,都判断一下左边和右边是否能和当前的数字接起来,我这样 ...
- Curl的编译
下载 curl的官网:https://curl.haxx.se/ libcurl就是一个库,curl就是使用libcurl实现的. curl是一个exe,也可以说是整个项目的名字,而libcurl就是 ...
- Objective-C 之同步请求、异步请求、GET请求、POST请求
本篇文章由:http://www.sollyu.com/objective-c-synchronization-requests-requests-for-asynchronous-requests- ...
- Headfirst设计模式的C++实现——迭代器(Iterator)
iterator.h #ifndef _ITERATOR_H_ #define _ITERATOR_H_ #include "menu_item.h" class Iterator ...
- javascript检测是否安装了flash
检测是否安装了flash function flashChecker() { var hasFlash = 0; //是否安装了flash var flashVersion = 0; //flash版 ...
- Unity3D--学习太空射击游戏制作(二)
步骤三:创建主角 游戏的主角是一艘太空飞船,我们将使用一个飞船模型作为游戏的主角,并赋予他一个脚本,控制他的运动,游戏体的组件必须依赖于脚本才能运行. 01:在Project窗口找到Player.fb ...