CodeForces 803A Maximal Binary Matrix
枚举。
枚举对角线上放多少个$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的更多相关文章
- 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 ...
- Maximal Binary Matrix CodeForces - 803A (贪心+实现)
题目链接 题意有点坑: 给你一个N*N的矩阵,让你填入K个1,使之整个矩阵关于左上到右下的对角线对称,并且这个要求这个矩阵的字典序最大. 对矩阵的字典序的定义是从每一行的第一个元素开始比较,大着为字典 ...
- Codeforces 884E E. Binary Matrix
题 OvO http://codeforces.com/contest/884/problem/E 884e 解 考虑并查集,每个点向上方和左方的点合并,答案即为1的总数减去需要合并的次数 由于只有1 ...
- 题解 CF803A Maximal Binary Matrix
Luogu codeforces 前言 模拟赛原题.. 好好一道送分被我硬打成爆蛋.. \(\sf{Solution}\) 看了一波数据范围,感觉能 dfs 骗分. 骗成正解了. 大概就是将这个 \( ...
- A.Kaw矩阵代数初步学习笔记 3. Binary Matrix Operations
“矩阵代数初步”(Introduction to MATRIX ALGEBRA)课程由Prof. A.K.Kaw(University of South Florida)设计并讲授. PDF格式学习笔 ...
- 【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 ...
- 【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 ...
- CodeForces 313C Ilya and Matrix
Ilya and Matrix Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Su ...
- codeforces 803C Maximal GCD(GCD数学)
Maximal GCD 题目链接:http://codeforces.com/contest/803/problem/C 题目大意: 给你n,k(1<=n,k<=1e10). 要你输出k个 ...
随机推荐
- Java设计模式の命令模式
意图: 将一个请求封装为一个对象,从而可用不同的请求对客户进行参数化:对请求排队或记录日志,以及支持可撤销的操作 动机: 将”发出请求的对象”和”接收与执行这些请求的对象”分隔开来. 效果: 1).c ...
- 用js实现千位分隔符
function mm(num) { return num && num .toString() .replace(/(\d)(?=(\d{3})+\.)/g, function($0 ...
- [LeetCode] 30. Substring with Concatenation of All Words ☆☆☆
You are given a string, s, and a list of words, words, that are all of the same length. Find all sta ...
- JAVA类与对象---实例变量与类变量的区别,实例方法和类方法的区别
实例变量 实例变量声明在一个类中,但在方法.构造方法和语句块之外: 当一个对象被实例化之后,每个实例变量的值就跟着确定: 实例变量在对象创建的时候创建,在对象被销毁的时候销毁: 实例变量的值应该至少被 ...
- 通过jquery.validate.js校验表单字段是否合法
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...
- flex实例(阮一峰)
Flex 布局教程:实例篇 作者: 阮一峰 日期: 2015年7月14日 上一篇文章介绍了Flex布局的语法,今天介绍常见布局的Flex写法. 你会看到,不管是什么布局,Flex往往都可以几行命令 ...
- 使用wifite破解路由器密码
使用wifite破解路由器密码 发表于 2016-02-06 | 分类于 wifite | 暂无评论 | 10次阅读 简介 wifite是一款自动化wep.wpa破解工具,不支持w ...
- VMware 克隆多台Linux机器并配置IP的方法
我们首先要知道 VMware 三种网络模式的区别. ①.Bridged(桥接模式):就是将主机网卡与虚拟机虚拟的网卡利用虚拟网桥进行通信.在桥接的作用下,类似于把物理主机虚拟为一个交换机,所有桥接设置 ...
- (正则表达式)linux shell 字符串操作(长度,查找,替换,匹配)详解
在做shell批处理程序时候,经常会涉及到字符串相关操作.有很多命令语句,如:awk,sed都可以做字符串各种操作. 其实shell内置一系列操作符号,可以达到类似效果,大家知道,使用内部操作符会省略 ...
- android 动态改变控件位置和大小 .
动态改变控件位置的方法: setPadding()的方法更改布局位置. 如我要把Imageview下移200px: ImageView.setPadding( ImageVie ...