Educational Codeforces Round 20 A
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 }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
· 三行代码完成国际化适配,妙~啊~