图论类型各题总结-acm.doc
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_05.gif)
《图论类型各题总结-acm.doc》由会员分享,可在线阅读,更多相关《图论类型各题总结-acm.doc(38页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、hdu4318 Power transmission 最短路 当数据很大的时候的解决办法 一道题目的解题全过程记录最短路 解决大数据模拟链表Power transmissionTime Limit: 10000/5000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 663 Accepted Submission(s): 231Problem DescriptionThe project WestEast power transmission is famous around t
2、he world。 It transmits the electricity from western areas to east China. There are many nodes in the power system。 Each node is connected with several other nodes in the system by cable。 Power can be only transmitted between two connected nodes。 For each node, it cant send power to two or more other
3、 nodes at the same time。As we have all known, power will be loss during the transmission。 Bob is the chief engineer of the project。 He wants to build a transmission line which send power from one node to another node and minimize the power loss at the same time。 Now he asks you to help him solve the
4、 problem。 InputThere are several test cases. For each test case, the first line contains an integer N (0 N 50000) which represents the number of nodes in the power system。 Then there will be N groups of data following。 For the i-th(0 i N) group, the first line is an integer ki (ki 50), which means t
5、he node i is connected with ki nodes. The rest of the ith group data are divided into ki lines. Each line contains an integer ai (0 2 4, loss power is 100 50 + 100 * (100-50)20 = 60.00MicrosoftInternetExplorer402DocumentNotSpecified7。8Normal0题意:多个点 从一个点往另一个点运输天然气 但是从某点到另外一点是会有损耗的 题中输入的即为损耗的百分数 问从点s到
6、t最少损耗多少 分析: 很明显是最短路问题 但是有个比较卡人的地方 就是最多会有50000个点 数据太大 用map数组存不下 会爆掉 我们考虑到用链表 就用了数组去模拟链表 保存从当前点能到达的点队长把写解题报告的任务光荣的交给了我 但是我对看代码表示相当的纠结 所以就自己去写了个 好理解 把自己的贴上 /#includestdio。hincludestruct hahaint son55; /记录从当前点到其它能走到的点double son_val55; /记录从当前点到其它能走到的点的消耗int cnt;/记录存取的儿子个数a50100;int n,flag,s,t,M,used50100
7、;double min50100;double find_short()/模拟以前数据比较小的时候的模板 int i,j,pos,cnt; double mm; memset(used,0,sizeof(used); for(i=1;i=n;i+) mini=1; cnt=t; while(cnt) minas。soncnt=as。son_valcnt; useds=1; mins=0; for(i=2;i=n;i+) mm=1; for(j=1;j=n;j+) if(!usedjmmminj) pos=j; mm=minj; if(mm=1) flag=1;return 0; usedpos
8、=1; cnt=apos。cnt; for(j=0;jcnt;j+) if(!usedapos。sonj&minpos+(1。0-minpos)*apos.son_valjminapos.sonj) minapos。sonj=minpos+(1.0minpos)apos。son_valj; if(pos=t) return mint;/这里很重要 不加会超时的哦 return mint;int main()int i,m,x,y;double val,k;while(scanf(d,n)!=EOF)flag=0;for(i=1;i=n;i+) ai。cnt=0;for(i=1;i#includ
9、estring。hint n,used1005;double map10051005,min1005;void find_short(int s)int i,j,pos;double mm;memset(used,0,sizeof(used);for(i=1;i=n;i+)mini=mapsi;mins=1;useds=1;for(i=2;i=n;i+)pos=0;mm=-1;for(j=1;j=n;j+)if(!usedj&mmminj)pos=j;mm=minj;usedpos=1;if(mm=1) break;for(j=1;jminj)minj=minpos*mapposj;int m
10、ain()int i,j,m,s,e;while(scanf(”d”,n)!=EOF)for(i=1;i=n;i+)for(j=1;jc1-.。.。ck-dTotal cost : .。.。.。.From e to f :Path: e-e1-。.。.。.。-ek-fTotal cost : 。.。Note: if there are more minimal paths, output the lexically smallest one。 Print a blank line after each test case。 Sample Input50 3 22 -1 43 0 5 -1 12
11、2 5 0 9 20-1 1 9 0 44 1 20 4 05 17 8 3 11 33 52 41 10 Sample OutputFrom 1 to 3 :Path: 154-3Total cost : 21From 3 to 5 :Path: 3-4-5Total cost : 16From 2 to 4 :Path: 2-1-5-4Total cost : 17#includestdio。hincludestring.h#define size 1000int valsize,mapsizesize,usedsize,minsize,n,startsize,endsize,flag,p
12、resize;char s11300,s21300;int ok(int n1,int n2,int s)/比较字典序大小int i,k; i=0; s1i+=n1+0; k=pren1; while(k!=s) s1i+=k+0;k=prek; s1i+=s+0; s1i=0; strrev(s1);/把字符串翻转过来 i=0; s2i+=n1+0; k=n2;/因为依然是n1(j)为最后一个 通过n2(pos)架桥 while(k!=s) s2i+=k+0;k=prek; s2i+=s+0; s2i=0; strrev(s2); if(strcmp(s2,s1)0)return 1; el
13、se return 0;void find_short(int s)int i,j,mm,pos;memset(used,0,sizeof(used));for(i=1;i=n;i+)mini=mapsi;if(mapsi!=999999999) /这一步居然忘记了 阿弥陀佛 记住这个千万不能少prei=s;mins=0;useds=1;for(i=2;i=n;i+)mm=999999999;for(j=1;j=n;j+)if(!usedj&mmminj)pos=j;mm=minj;if(mm=999999999) break;usedpos=1;for(j=1;j=n;j+)if(!used
14、j&minpos+mapposj+valposminj)minj=minpos+mapposj+valpos;prej=pos;elseif(!usedjminpos+mapposj+valpos=minj)if(ok(j,pos,s) prej=pos;/如果pos之前的字典序较小那么更新void print(int s,int e)int asize,i,k;k=0;ak+=e;i=e;while(s!=i)i=prei;ak+=i;printf(”Path: ”);for(i=k1;i0;i)printf(”d-,ai);printf(”dn,a0);int main()int i,j,
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 类型 总结 acm
![提示](https://www.taowenge.com/images/bang_tan.gif)
限制150内