poj1860 Bellman_Ford算法

本文介绍了一个货币兑换问题,通过一系列的兑换操作,在不重复使用同一兑换点的情况下,判断是否能够从初始货币金额出发,经过一系列合法的操作后,最终获得比初始金额更多的相同货币。文章提供了一种基于Bellman-Ford算法的解决方案。
Currency Exchange
Time Limit: 1000MS Memory Limit: 30000K
Total Submissions: 21922 Accepted: 7910

Description

Several currency exchange points are working in our city. Let us suppose that each point specializes in two particular currencies and performs exchange operations only with these currencies. There can be several points specializing in the same pair of currencies. Each point has its own exchange rates, exchange rate of A to B is the quantity of B you get for 1A. Also each exchange point has some commission, the sum you have to pay for your exchange operation. Commission is always collected in source currency. 
For example, if you want to exchange 100 US Dollars into Russian Rubles at the exchange point, where the exchange rate is 29.75, and the commission is 0.39 you will get (100 - 0.39) * 29.75 = 2963.3975RUR. 
You surely know that there are N different currencies you can deal with in our city. Let us assign unique integer number from 1 to N to each currency. Then each exchange point can be described with 6 numbers: integer A and B - numbers of currencies it exchanges, and real RAB, CAB, RBA and CBA - exchange rates and commissions when exchanging A to B and B to A respectively. 
Nick has some money in currency S and wonders if he can somehow, after some exchange operations, increase his capital. Of course, he wants to have his money in currency S in the end. Help him to answer this difficult question. Nick must always have non-negative sum of money while making his operations. 

Input

The first line of the input contains four numbers: N - the number of currencies, M - the number of exchange points, S - the number of currency Nick has and V - the quantity of currency units he has. The following M lines contain 6 numbers each - the description of the corresponding exchange point - in specified above order. Numbers are separated by one or more spaces. 1<=S<=N<=100, 1<=M<=100, V is real number, 0<=V<=103
For each point exchange rates and commissions are real, given with at most two digits after the decimal point, 10-2<=rate<=102, 0<=commission<=102
Let us call some sequence of the exchange operations simple if no exchange point is used more than once in this sequence. You may assume that ratio of the numeric values of the sums at the end and at the beginning of any simple sequence of the exchange operations will be less than 104

Output

If Nick can increase his wealth, output YES, in other case output NO to the output file.

Sample Input

3 2 1 20.0
1 2 1.00 1.00 1.00 1.00
2 3 1.10 1.00 1.10 1.00

Sample Output

YES
 1 #include<stdio.h>
 2 #include<string.h>
 3 
 4 struct Node{
 5     int u,v;    // 起点,终点
 6     double r,c;
 7 };
 8 
 9 Node edge[221]; bool flg;
10 double dis[110];
11 
12 int nodenum, edgenum, source,t;    // 结点数,边数,源点,起始值,总边数
13 double V;
14 
15 void relax(int u,int v,double r,double c)   //*用double 
16 {
17     if(dis[v]<(dis[u]-c)*r);
18         dis[v]=(dis[u]-c)*r;
19 }
20 
21 bool Bellman_Ford()
22 {
23     int i,j,k;
24     for(i=1;i<=nodenum;i++)
25         dis[i]=0;
26     dis[source]=V;
27 
28     for(i=1;i<=nodenum-1;i++)
29     {
30         for(j=1;j<=t;j++)                   //*注意是总边数
31         {
32             relax(edge[j].u,edge[j].v,edge[j].r,edge[j].c);
33         }
34         /*flg=false;   //优化做法
35         for(j=1;j<=t;j++)
36         {
37             if(dis[edge[j].v] < (dis[edge[j].u]-edge[j].c)*edge[j].r)//求最大
38             {
39                 //flg=true;
40                 dis[edge[j].v]=(dis[edge[j].u]-edge[j].c)*edge[j].r;
41             }
42         }
43         if(!flg) return false;*/
44     }
45     //judge
46 
47     for(i=1;i<=t;i++)
48     {
49         if(dis[edge[i].v]<(dis[edge[i].u]-edge[i].c)*edge[i].r)
50             return true;
51     }
52     return false;
53 }
54 
55 
56 int main()
57 {
58     int i,j,k;
59     while(scanf("%d %d %d %lf",&nodenum,&edgenum,&source,&V)!=EOF)
60     {
61         t=1;
62         for(i=1;i<=edgenum;i++)
63         {
64             scanf("%d %d %lf %lf",&edge[t].u,&edge[t].v,&edge[t].r,&edge[t].c);
65             t++;
66             edge[t].u=edge[t-1].v,edge[t].v=edge[t-1].u;
67             scanf("%lf %lf",&edge[t].r,&edge[t].c);
68             t++;
69         }
70         t--;                    //总边数值
71         if(Bellman_Ford()==true)
72             printf("YES\n");
73         else
74             printf("NO\n");
75     }
76     return 0;
77 }
View Code

 

转载于:https://www.cnblogs.com/cyd308/p/4539453.html

跟网型逆变器小干扰稳定性分析与控制策略优化研究(Simulink仿真实现)内容概要:本文围绕跟网型逆变器的小干扰稳定性展开分析,重点研究其在电力系统中的动态响应特性及控制策略优化问题。通过构建基于Simulink的仿真模型,对逆变器在不同工况下的小信号稳定性进行建模与分析,识别系统可能存在的振荡风险,并提出相应的控制优化方法以提升系统稳定性和动态性能。研究内容涵盖数学建模、稳定性判据分析、控制器设计与参数优化,并结合仿真验证所提策略的有效性,为新能源并网系统的稳定运行提供理论支持和技术参考。; 适合人群:具备电力电子、自动控制或电力系统相关背景,熟悉Matlab/Simulink仿真工具,从事新能源并网、微电网或电力系统稳定性研究的研究生、科研人员及工程技术人员。; 使用场景及目标:① 分析跟网型逆变器在弱电网条件下的小干扰稳定性问题;② 设计并优化逆变器外环与内环控制器以提升系统阻尼特性;③ 利用Simulink搭建仿真模型验证理论分析与控制策略的有效性;④ 支持科研论文撰写、课题研究或工程项目中的稳定性评估与改进。; 阅读建议:建议读者结合文中提供的Simulink仿真模型,深入理解状态空间建模、特征值分析及控制器设计过程,重点关注控制参数变化对系统极点分布的影响,并通过动手仿真加深对小干扰稳定性机理的认识。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值