Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=1285
The main idea: someone knows the outcome of the N-Team M-field match, requires the output of n teams (ID is the second keyword).
Core idea: Transform to graph theory problem, make topological sort. Step 1. Point 2 with a selected degree of 0. Delete the point with the associated Edge 3. Repeat the process
The code is as follows:
Topology sequencing (1. The point with the selected degree of 0. 2. Delete the point and the associated Edge 3. Repeat the process) #include <iostream> #include <memory.h>using namespace Std;int map[510][510];//map[0][ I] for the entry of the I point int m,n;void clear (int N) {//delete associative edge for (int i=1;i<=n;i++) {if (map[n][i]==1) {map[n][i]=0 ; map[0][i]--; }} return; void Solve () {int target; int cnt=0; BOOL Flag=false; for (int i=1;i<=n;i++) {if (map[0][i]==0) {cnt++; cout<<i; Clear (i); map[0][i]--; i=0;//is critical, if (cnt==n) cout<<endl; else cout<< ""; }} return; int main () {int x,y,cnt=0; while (cin>>n>>m) {memset (map,0,sizeof (MAP)); while (m--) {cin>>x>>y; if (! Map[x][y]) {map[x][y]=1; map[0][y]++; }} for (int i=1;i<=n;i++) {if (map[0][i]==0) cnt++; } if (cnt==0) map[0][1]=0;//asThe fruit is the ring to be treated so, 1 for the beginning solve (); } return 0;}
HDU[1285] Determine the ranking of the competition ranking topology