hdu 1285 确定比赛名次
2016-05-01 12:53
253 查看
几个月前学了的邻接表是时候复习一下了。。
从最简单的做起。。
邻接表比邻接矩阵快了2倍啊。。 好厉害
邻接矩阵就不放了。。
从最简单的做起。。
邻接表比邻接矩阵快了2倍啊。。 好厉害
#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #include<string> using namespace std; struct node { int who; int cnt; node *next; }way[510]; int find(int a,int b) { for(node *p=way[a].next;p;p=p->next) { if(p->who==b) { return 1; } } return 0; } void add(int a,int b) { if(!find(a,b)) { way[b].cnt++; node *p=new node; p->next=way[a].next; p->who=b; way[a].next=p; } } int main() { int n,m; while(cin>>n>>m) { for(int i=1;i<=n;i++) { way[i].cnt=0; way[i].next=NULL; } int a,b; while(m--) { cin>>a>>b; add(a,b); } for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) { if(way[j].cnt==0) { way[j].cnt--; if(i!=n) { cout<<j<<" "; } else { cout<<j<<endl; } for(node *p=way[j].next;p;p=p->next) { way[p->who].cnt--; } break; } } } } return 0; }
邻接矩阵就不放了。。
相关文章推荐
- Java:存储可变大小的二维数组
- 【HDU 5366】The mook jong 详解
- 【HDU 2136】Largest prime factor 详细图解
- 【HDU 1568】Fibonacci 数学公式 详解
- HDU 1568
- HDU1290
- HDU1568(Fobonacci公式)
- HDU ACM Step 2.2.2 Joseph(约瑟夫环问题)
- HDU 1405
- HDU 1297
- hdu 1205
- hdu 2087
- hdu 1016
- HDU 4898 The Revenge of the Princess’ Knight ( 2014 Multi-University Training Contest 4 )
- HDU 5592 ZYB's Premutation 线段树(查找动态区间第K大)
- 图的邻接表存储
- HDU 5240 Exam (好水的题)
- HDU5237 Base64 大模拟
- HDU 1000
- HDU 1001