标签:des style blog java color os strong 数据
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 11543 Accepted Submission(s): 4603
6 11 5 3 5 3 5 1 5 4 5 2 3 1 3 2 6 4 6 2 4 2 4 2 结果是: 5 3 1 6 4 2
代码:
1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 #include <iostream> 5 #include <stack> 6 #include <queue> 7 #include <map> 8 #include <vector> 9 #include <sstream> 10 #include <string> 11 using namespace std; 12 13 struct mem{ 14 int x, y; 15 }a[505]; 16 17 bool cmp(mem a,mem b){ 18 if(a.x==b.x) return a.y<b.y; 19 return a.x<b.x; 20 } 21 22 main() 23 { 24 int du[505]; 25 int ma[505][505]; 26 vector<int>ve[505]; 27 int n, m, i, j, k; 28 while(scanf("%d %d",&n,&m)==2){ 29 memset(du,0,sizeof(du)); 30 memset(ma,0,sizeof(ma)); 31 for(i=0;i<=n;i++) ve[i].clear(); 32 for(i=0;i<m;i++) { 33 scanf("%d %d",&a[i].x,&a[i].y); 34 if(!ma[a[i].x][a[i].y]) 35 { 36 du[a[i].y]++; 37 ve[a[i].x].push_back(a[i].y); 38 } 39 40 ma[a[i].x][a[i].y]=1; 41 } 42 // sort(a,a+m,cmp); 43 /* 44 for(i=1;i<=n;i++){ 45 printf("%d ",du[i]); 46 } 47 cout<<endl<<endl;*/ 48 int b[505], f=0, l=0; 49 for(k=1;k<=n;k++){ 50 f=0; 51 for(i=1;i<=n;i++){ 52 if(du[i]==0) { 53 for(j=0;j<ve[i].size();j++){ 54 du[ve[i][j]]--; 55 } 56 b[l++]=i; 57 du[i]=-1; 58 f++; 59 break; 60 } 61 62 } 63 if(!f) break; 64 } 65 printf("%d",b[0]); 66 for(i=1;i<l;i++) printf(" %d",b[i]); 67 cout<<endl; 68 69 } 70 }
标签:des style blog java color os strong 数据
原文地址:http://www.cnblogs.com/qq1012662902/p/3871773.html