CodeForces 803A Maximal Binary Matrix
来源:互联网 发布:淘宝直通车关键词查询 编辑:程序博客网 时间:2024/06/05 07:59
题目链接:http://codeforces.com/contest/803/problem/A
题意:给你一个n*n的矩阵,让你往里面填1,使得这个矩阵对称,然后输出这个矩阵字典序最大的那个矩阵,如果无法完成就输出-1,矩阵字典序就是每行都进行字典序比较
解析:带点贪心的构造题,首先k>n*N肯定是输出-1,剩下的,由于是要输出字典序最大的,那么肯定是尽可能把每一行都填满,但是要对称着填,对角线上消耗一个1,其余地方消耗两个1
#include <bits/stdc++.h>using namespace std;const int maxn = 100+50;int a[maxn][maxn];int main(void){ int n,k; scanf("%d %d",&n,&k); int flag = 1; if(k>n*n) flag = 0; else { for(int i=0;i<n;i++) { if(k<1) break; a[i][i] = 1; k--; for(int j=i+1;j<n;j++) { if(k<2) break; a[i][j] = a[j][i] = 1; k-=2; } } if(k) flag = 0; } if(flag) { for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { if(j)printf(" "); printf("%d",a[i][j]); } puts(""); } } else puts("-1"); return 0;}
0 0
- Codeforces 803 A. Maximal Binary Matrix (模拟
- Codeforces 803A Maximal Binary Matrix 题解
- CodeForces 803A Maximal Binary Matrix
- 【CodeForces 803A】Maximal Binary Matrix(模拟)
- CodeForces 803A Maximal Binary Matrix-【思维+构造】
- 803A Maximal Binary Matrix
- CF#803 A. Maximal Binary Matrix(贪心)
- Educational Codeforces Round 20 Maximal Binary Matrix
- Codeforces803A Maximal Binary Matrix
- Maximal Square,Given a 2D binary matrix filled with 0's and 1's, find the largest squar
- CodeForces 364A Matrix
- codeforces 803C Maximal GCD
- 【Codeforces 803 C. Maximal GCD】
- CodeForces-263A-Beautiful Matrix
- codeforces 263A Beautiful Matrix
- Codeforces 803C Maximal GCD 题解
- Codeforces 803C Maximal GCD【思维】
- Codeforces 825 A Binary Protocol
- nginx配置location总结及rewrite规则写法
- C语言精要总结-内存地址对齐与struct大小判断篇
- JAVA随笔——关于编码
- bzoj 4070: [Apio2015]雅加达的摩天楼 最短路+分块
- C#/.NET中关于目录路径的问题
- CodeForces 803A Maximal Binary Matrix
- SIGSEGV
- Java 单例模式
- Java中UDP、TCP及HTTP通信
- 主键约束和唯一性约束的区别
- 在子类中,一定要访问父类的有参方法?
- js格式化时间类的方法
- 机器学习面试算法
- jboss启动报错Could not make local copy for file解决方法