Resistance
题意:
给出一个由n个节点和m个二元电阻元件组成的电路,求问节点1到节点n的等效电阻。
解法:
应用电子电路分析中的基尔霍夫定律,对于每一个点有流量平衡,得
对于点$x$有 $$I_{出} + \sum_{<i,x>∈|E|}{\frac{U_x-U_i}{R_{x,i}}} = I_{入}$$
规定从点1流入$1A$的电流,从点n流出$1A$的电流,得到n个关于$U_i$的方程。
注意到n个方程最大线性无关组为 n-1个方程,解出来是$x = k* \eta + \xi$,从而要引入一个新的方程。
(因为限制流入1的电流是$1A$的方程是多余的)
只要将点1的方程改成 $U_1 = 0V$ 即可。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <cmath> #define N 110
#define LD double
#define eps 1e-13 using namespace std; int n,m,tot;
LD u[N],a[N][N]; LD Gauss(LD a[N][N],int n)
{
int cnt=;
for(int i=;i<=n;i++)
{
int t=;
for(int j=i;j<=n;j++)
if(fabs(a[j][i])>eps)
{
t=j;
break;
}
if(!t)
{
cnt++;
continue;
}
for(int j=;j<=n+;j++) swap(a[i][j],a[t][j]);
for(int j=i+;j<=n+;j++) a[i][j]/=a[i][i];
a[i][i]=1.0;
for(int j=;j<=n;j++)
{
if(j==i) continue;
for(int k=i+;k<=n+;k++)
a[j][k] -= a[j][i]*a[i][k];
a[j][i]=;
}
}
return a[n][n+]/a[n][]- a[][n+]/a[][n];
} int main()
{
// freopen("test.txt","r",stdin);
while(~scanf("%d%d",&n,&m))
{
memset(a,,sizeof(a));
int x,y;
LD R;
for(int i=;i<=m;i++)
{
scanf("%d%d%lf",&x,&y,&R);
LD tmp=1.0/R;
a[x][x]+=tmp;
a[y][y]+=tmp;
a[x][y]-=tmp;
a[y][x]-=tmp;
}
a[][]=;
for(int i=;i<=n;i++) a[][i]=;
a[][n+]=;
a[n][n+]=;
printf("%.2f\n",Gauss(a,n));
}
return ;
}
Resistance的更多相关文章
- The Non-Inverting Amplifier Output Resistance by Adrian S. Nastase [ Copied ]
		Source Address: http://masteringelectronicsdesign.com/the-non-inverting-amplifier-output-resistance/ ... 
- codeforces343A A. Rational Resistance
		http://http://codeforces.com/problemset/problem/343/A A. Rational Resistance time limit per test 1 s ... 
- Codeforces Round #200 (Div. 1)A. Rational Resistance 数学
		A. Rational Resistance Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/343 ... 
- New Lantern Version Available Upgrade Lantern for improved blocking resistance!
		New Lantern Version Available Upgrade Lantern for improved blocking resistance! The new version: is ... 
- hug and Compression Resistance
		Hugging => content does not want to grow Compression Resistance => content does not want to sh ... 
- AutoLayout学习之理解intrinsicContentSize,Content Hugging Priority,Content Compression Resistance Priority
		TableViewCell的高度计算应该是所有开发者都会使用到的东西,之前都是用代码计算的方法来计算这个高度.最近有时间看了几个计算Cell高度的方法.基本上都用到了AutoLayout,这篇首先介绍 ... 
- Codeforces Round #200 (Div. 2) C. Rational Resistance
		C. Rational Resistance time limit per test 1 second memory limit per test 256 megabytes input standa ... 
- iOS开发之AutoLayout中的Content Hugging Priority和 Content Compression Resistance Priority解析
		本篇博客的内容也不算太复杂,算是AutoLayout的一些高级的用法.本篇博客我们主要通过一些示例来看一下AutoLayout中的Content Hugging Priority以及Content C ... 
- The Non-Inverting Amplifier Output Resistance by Adrian S. Nastase [转载]
		Source Address: http://masteringelectronicsdesign.com/the-non-inverting-amplifier-output-resistance/ ... 
- HDU 3976 Electric resistance (高斯消元法)
		Electric resistance Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ... 
随机推荐
- 修改mysql数据库 密码
			将密码改成123456 update mysql.user set authentication_string=password('123456') where user='root' and Hos ... 
- EasyDarwin开源流媒体服务器将select改为epoll的方法
			本文来自EasyDarwin团队Fantasy(fantasy(at)easydarwin.org) 一. EasyDarwin网络模型介绍 EventContext负责监听所有网络读写事件,Even ... 
- memcmp和strcmp的返回值
			注意,无论是内存比较还是字符串比较,这两个函数的返回值的意义是一样的. 如果相同,返回0 如果前面大于后面,返回大于0 如果前面小于后面,返回小于0 一定要注意,相同的时候是0,不是true. 
- Conditions in bash scripting (if statements)
			Shell中判断语句if中-z至-d的意思 - sunny_2015 - 博客园 https://www.cnblogs.com/coffy/p/5748292.html Conditions in ... 
- 使用Windows API发送HTTP请求
			先看一个简单的GET示例 #include <Windows.h> #include <winhttp.h> #include <stdio.h> int main ... 
- FireMonkey下的WndProc实现
			unit Unit1; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Types, System.UI ... 
- JSOI2004 平衡点 / 吊打XXX
			题目描述 有n个重物,每个重物系在一条足够长的绳子上.每条绳子自上而下穿过桌面上的洞,然后系在一起.图中X处就是公共的绳结.假设绳子是完全弹性的(不会造成能量损失),桌子足够高(因而重物不会垂到地上) ... 
- 怎样把word直接转换成ppt
- ./autogen.sh: 4: autoreconf: not found
			./autogen.sh: 4: autoreconf: not found 是在不同版本的 tslib 下执行 autogen.sh 产生.它们产生的原因一样,是因为没有安装 automake ... 
- ZOJ - 3948 Marjar Cola 【循环】
			题目链接 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3948 题意 用 x 个 瓶身 可以 换 一瓶饮料 用 y 个 瓶 ... 
