HDU 4948
I am sorry for this question. After reading this question, I thought it was quite simple.
At the beginning, I thought about Topology Sorting, and then I thought about it ...... This is the reverse order of topological sorting, and then we find that it is quite watery ......
If you want to develop a city, you must have another city as the prerequisite for its development. That is, if the City U-> W is connected, you must develop the city w, the premise is that u is already a developed city. That's not very easy.
That is to say, the first city to be developed is the city with the highest degree of output, because u-> W can see that the largest degree of output is sorted in ascending order.
Oh, it's a pity, because I saw no one handed in this question, and then did not dare to tell my teammates what I wanted, and I didn't even think about it ...... Then, I missed the opportunity to enter the first version of the project. It was really broken down by the first echelon ......
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<map>#include<queue>#include<set>#include<cmath>#include<bitset>#define mem(a,b) memset(a,b,sizeof(a))#define lson i<<1,l,mid#define rson i<<1|1,mid+1,r#define llson j<<1,l,mid#define rrson j<<1|1,mid+1,r#define INF 0x7fffffff#define maxn 11010using namespace std;typedef long long ll;typedef unsigned long long ull;char s[500][505];struct abc{ int i,out; bool operator<(const abc &a)const { return out>a.out; }}a[501];int main(){ //freopen("1.txt","r",stdin); int n,i,j; while(scanf("%d",&n)&&n) { for(i=0;i<n;i++) scanf("%s",s[i]),a[i].i=i,a[i].out=0; for(i=0;i<n;i++) for(j=0;j<n;j++) if(s[i][j]=='1') a[i].out++; sort(a,a+n); printf("%d",a[0].i+1); for(i=1;i<n;i++) printf(" %d",a[i].i+1); puts(""); } return 0;}