枚举。

枚举对角线上放多少个$1$,剩余的贪心放,更新答案。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
using namespace std; int n,k;
int a[110][110];
int b[110][110]; void ok()
{
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
if(a[i][j]!=b[i][j])
{
if(a[i][j]>b[i][j])
{
for(int ii=1;ii<=n;ii++)
{
for(int jj=1;jj<=n;jj++)
{
b[ii][jj] = a[ii][jj];
}
} }
return ;
}
}
}
} int main()
{
scanf("%d%d",&n,&k);
if(n*n<k)
{
printf("-1\n");
return 0;
} int suc = 0; for(int x=0;x<=n;x++)
{
memset(a,0,sizeof a); if(x>k) continue;
if((k-x)%2!=0) continue;
if( n*n - n < k-x ) continue; for(int i=1;i<=x;i++) a[i][i] = 1; int sum = 0;
if((k-x)!=0)
{
for(int i=1;i<=n;i++)
{
for(int j=i+1;j<=n;j++)
{
a[i][j] = a[j][i]=1;
sum+=2;
if(sum == k-x) break;
}
if(sum == k-x) break;
}
} if(sum == k-x) suc=1;
ok();
} if(suc==0) printf("-1\n");
else
{
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
printf("%d",b[i][j]);
if(j<n) printf(" ");
else printf("\n");
}
}
} return 0;
}

CodeForces 803A Maximal Binary Matrix的更多相关文章

  1. Educational Codeforces Round 20 A. Maximal Binary Matrix

    A. Maximal Binary Matrix time limit per test 1 second memory limit per test 256 megabytes input stan ...

  2. Maximal Binary Matrix CodeForces - 803A (贪心+实现)

    题目链接 题意有点坑: 给你一个N*N的矩阵,让你填入K个1,使之整个矩阵关于左上到右下的对角线对称,并且这个要求这个矩阵的字典序最大. 对矩阵的字典序的定义是从每一行的第一个元素开始比较,大着为字典 ...

  3. Codeforces 884E E. Binary Matrix

    题 OvO http://codeforces.com/contest/884/problem/E 884e 解 考虑并查集,每个点向上方和左方的点合并,答案即为1的总数减去需要合并的次数 由于只有1 ...

  4. 题解 CF803A Maximal Binary Matrix

    Luogu codeforces 前言 模拟赛原题.. 好好一道送分被我硬打成爆蛋.. \(\sf{Solution}\) 看了一波数据范围,感觉能 dfs 骗分. 骗成正解了. 大概就是将这个 \( ...

  5. A.Kaw矩阵代数初步学习笔记 3. Binary Matrix Operations

    “矩阵代数初步”(Introduction to MATRIX ALGEBRA)课程由Prof. A.K.Kaw(University of South Florida)设计并讲授. PDF格式学习笔 ...

  6. 【leetcode】1284. Minimum Number of Flips to Convert Binary Matrix to Zero Matrix

    题目如下: Given a m x n binary matrix mat. In one step, you can choose one cell and flip it and all the ...

  7. 【leetcode】1253. Reconstruct a 2-Row Binary Matrix

    题目如下: Given the following details of a matrix with n columns and 2 rows : The matrix is a binary mat ...

  8. CodeForces 313C Ilya and Matrix

    Ilya and Matrix Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Su ...

  9. codeforces 803C Maximal GCD(GCD数学)

    Maximal GCD 题目链接:http://codeforces.com/contest/803/problem/C 题目大意: 给你n,k(1<=n,k<=1e10). 要你输出k个 ...

随机推荐

  1. 线上Redis偶发性链接失败排查记

    问题过程 输入法业务于12月12日上线了词库接受业务,对部分用户根据用户uuid判断进行回传,在12月17日早上8点多开始出现大量的php报错(Redis went away),报错导致了大量的链接积 ...

  2. powerdesigner中把表的描述复制到Name

    '****************************************************************************** '* File: comment2nam ...

  3. swift开发常用代码片段

    // 绑定事件 cell.privacySwitch.addTarget(self, action: #selector(RSMeSettingPrivacyViewController.switch ...

  4. HTML不常用的表单属性-fieldset

    这是代码 这是生成的样子 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http: ...

  5. 将new Date() 格式化为 ’2018-10-11‘ 的字符串格式

    function dateToString( date , format ){ if(!date) return ""; if (!Common.type.isDate(date) ...

  6. DOM操作二三事

    我突然想起了append(),但是我记不太清它是原生JS的还是jQuery封装的,貌似是JS的,咦?那它在jQuery里叫什么来着?哎呀!记不清了!确定append()是JS里的?不是jQuery里的 ...

  7. max-device-width和max-width的区别

    比如用媒体查询响应输出@media (max-width: 767px),用谷歌浏览器手机测试插件显示并无变化,其实关键在于max-device-width和max-width,以下摘抄↓ max-d ...

  8. DevExpress使用教程:GridView经验小结(官方中文文献经典资料技巧)

    下面是笔者自己总结的使用 DevExpress Gridview 的一些经验小结,分享给大家: 1.去除 GridView 头上的 "Drag a column header here to ...

  9. GridControl详解(三)列数据的格式设置

    为了测试方便,我们加入新的3列,格式分别是数据,时间,字符串.代码增加下列部分: //格式增加 dt.Columns.Add("数据",typeof(decimal)); dt.C ...

  10. 12款jQuery幻灯片插件和幻灯片特效教程

    jQuery 使用简单灵活,同时还有许多成熟的插件可供选择,它可以帮助你在项目中加入一些非常好的效果.滑块和幻灯片效果是常用的内容展示方式之一,这是一种在有限的网页空间内展示系列项目时非常好的方法.今 ...