标签:++ 矩阵 desc specific code rip diagonal tin size
Description
You are given matrix with n rows and n columns filled with zeroes. You should put k ones in it in such a way that the resulting matrix is symmetrical with respect to the main diagonal (the diagonal that goes from the top left to the bottom right corner) and is lexicographically maximal.
One matrix is lexicographically greater than the other if the first different number in the first different row from the top in the first matrix is greater than the corresponding number in the second one.
If there exists no such matrix then output -1.
The first line consists of two numbers n and k (1?≤?n?≤?100, 0?≤?k?≤?106).
If the answer exists then output resulting matrix. Otherwise output -1.
2 1
1 0
0 0
3 2
1 0 0
0 1 0
0 0 0
2 5
-1
题意:问如何将二进制矩阵排成字典序最大(需要主对角线对称)
解法:当然是这种啦,如果发现还有剩余1就输出-1
1 1 1 1 1 1 1 1 1...
1 1
1 1
1 .
1 .
1 #include<bits/stdc++.h> 2 using namespace std; 3 #define ll long long 4 const int maxn=654321; 5 int x[200][200]; 6 int n; 7 int num; 8 int main() 9 { 10 cin>>n>>num; 11 for(int i=1;num>0&&i<=n;i++) 12 { 13 x[i][i]=1; 14 num--; 15 for(int j=i+1;num>1&&j<=n;j++) 16 { 17 x[i][j]=x[j][i]=1; 18 num-=2; 19 } 20 } 21 if(num>0) 22 { 23 cout<<"-1"<<endl; 24 return 0; 25 } 26 for(int i=1;i<=n;i++) 27 { 28 for(int j=1;j<=n;j++) 29 { 30 cout<<x[i][j]<<" "; 31 } 32 cout<<endl; 33 } 34 return 0; 35 }
Educational Codeforces Round 20 A
标签:++ 矩阵 desc specific code rip diagonal tin size
原文地址:http://www.cnblogs.com/yinghualuowu/p/6792572.html