[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 ...
随机推荐
- 通用安全字符串输入,彻底替换server.htmlencode
Function HTMLEncode(Str) If Isnull(Str) Then HTMLEncode = "" Exit Function End If Str = Re ...
- C#学习笔记6:各种字符串问题
1.字符串 逐字字符串字面量:字符串前加@,不仅将反斜杠当做普通字符来处理,而且还会逐字解释所有空白字符. 如: Class Triangle { Static void Main() { Syste ...
- Java中内存空间的分配及回收
Java中内存分为: 栈:存放简单数据类型变量(值和变量名都存在栈中),存放引用数据类型的变量名以及它所指向的实例的首地址. 堆:存放引用数据类型的实例. Java的垃圾回收: 由一个后台线程GC(G ...
- 【原创】java 流星划过天空
import java.awt.Color; import java.awt.Graphics; import java.awt.image.BufferedImage; import javax.s ...
- UDP通信 Java
public class UdpServerTest { /** * @param args * @throws SocketException */ public static void main( ...
- 修改Latex常用编辑器WinEdt中的字号与字体 [转]
用latex编写科技文章已经是大多数科研工作者采用的方法,其编写效果是word所远不能及的.但是其效果只是在编译之后,之前文字那弱小的身躯确实令很多人无奈.10Pt的字体在以前14寸的电脑上看起来还是 ...
- jq选取对象的方法
$("#找id的")$(".找样式的") $("div[id]") 选择所有含有id属性的div元素 $("input[nam ...
- GridView 自定义表头
//修改表头 protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e) { switch (e.Row.Ro ...
- MySql的安装与使用
今天因为毕业设计要用到MySql数据库,所以就准备自己安装一个MySQL数据库,但是因为MySQL Install MSI只有32位,所以最后选择使用Windows (x86, 64-bit), ZI ...
- A Case Study -- Performance Evaluation of a DRAM-Based Solid State Disk
研究将固态硬盘作为持久存储层和传统硬盘的在数据库性能上的研究