A. Maximal Binary Matrix
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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.

Input

The first line consists of two numbers n and k (1 ≤ n ≤ 100, 0 ≤ k ≤ 106).

Output

If the answer exists then output resulting matrix. Otherwise output -1.

Examples
input
2 1
output
1 0 
0 0
input
3 2
output
1 0 0 
0 1 0
0 0 0
input
2 5
output
-1

昨晚模拟的时候脑残了,把这个字典序搞复杂了许多,还有在主对角线填1的时候比较迷。早上一想不就是每行对称先填啊,只要不是1就可以填两个数的,先填主对角线啊填的过程中k的个数是奇数也填啊,最后你怎么搞a[n][n]也是可以填的,巧妙避开了你填错的的问题。随便模拟下就过了。
#include <stdio.h>
int a[][];
int main()
{int n,k;
scanf("%d%d",&n,&k);
for(int i=;i<=n;i++){
if(!k)break;
else{
a[i][i]=;
k--;
}
for(int j=i+;j<=n;j++){
if(k<=)
break;
else{
a[i][j]=a[j][i]=;
k-=;
}
}
}
if(k)
printf("-1");
else{
for(int i=;i<=n;i++){
printf("%d",a[i][]);
for(int j=;j<=n;j++)
printf(" %d",a[i][j]);
printf("\n");
}}
return ;
}

Educational Codeforces Round 20 A. Maximal Binary Matrix的更多相关文章

  1. Educational Codeforces Round 20 C. Maximal GCD

    C. Maximal GCD time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  2. Educational Codeforces Round 20

    Educational Codeforces Round 20  A. Maximal Binary Matrix 直接从上到下从左到右填,注意只剩一个要填的位置的情况 view code //#pr ...

  3. Educational Codeforces Round 20 A

    Description You are given matrix with n rows and n columns filled with zeroes. You should put k ones ...

  4. Educational Codeforces Round 20 D. Magazine Ad

    The main city magazine offers its readers an opportunity to publish their ads. The format of the ad ...

  5. Educational Codeforces Round 20.C

    C. Maximal GCD time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  6. Educational Codeforces Round 20 C 数学/贪心/构造

    C. Maximal GCD time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  7. Educational Codeforces Round 20 C(math)

    題目鏈接: http://codeforces.com/problemset/problem/803/C 題意: 給出兩個數n, k, 將n拆分成k個數的和,要求這k個數是嚴格遞增的,並且這k個數的g ...

  8. Educational Codeforces Round 20 B. Distances to Zero

    B. Distances to Zero time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  9. Educational Codeforces Round 20 E - Roma and Poker(dp)

    传送门 题意 Roma在玩一个游戏,一共玩了n局,赢则bourle+1,输则bourle-1,Roma将会在以下情况中退出 1.他赢了k个bourle 2.他输了k个bourle 现在给出一个字符串 ...

随机推荐

  1. 最具士兵突击实战类型的JavaScript

    JavaScript实战一书的基础知识部分帮助读者快速踏入JavaScript领域之门,jQuery部分帮助读者随心所欲地去工作,HTML5部分帮读者搭上时代的班车,Node.JS则可以让读者屹立在技 ...

  2. sshd_config配置注释

    # $OpenBSD: sshd_config,v 1.80 2008/07/02 02:24:18 djm Exp $ # This is the sshd server system-wide c ...

  3. javaSe-hashMap

    package com.java.chap08.sec05; public class Student { private String name; private Integer age; publ ...

  4. 用python写trojan的过程中遇到的各种问题

    由于之前已经conn, addr = s.accept() 所以改为  conn.recv spyder无法同时运行client 和 server 分别在spyder和anaconda prompt运 ...

  5. WINDOWS-基础:LPTSTR

    1. LPTSTR解释 与char*等价,表示普通字符/字符串变量,指向字符/字符串的指针. LP:  长指针(long pointer). T:   win32环境中有一个_T宏,用来标识字符是否采 ...

  6. DROP LANGUAGE - 删除一个过程语言

    SYNOPSIS DROP [ PROCEDURAL ] LANGUAGE name [ CASCADE | RESTRICT ] DESCRIPTION 描述 DROP LANGUAGE 将删除曾注 ...

  7. python之道13

    看代码分析结果 func_list = [] for i in range(10): func_list.append(lambda :i) v1 = func_list[0]() v2 = func ...

  8. python - 辨识alert、window以及操作

    selenium之 辨识alert.window以及操作 原创 2016年08月24日 11:01:04 4820 0 2 更多关于python selenium的文章,请关注我的专栏:Python ...

  9. sql server 定时备份 脚本

    ) DECLARE @date DATETIME SELECT @date = GETDATE() SELECT @filename = 'G:\backup\NewPlulishSQL-' + CA ...

  10. React入门教程(二)

    前言 距离上次我写 React 入门教程已经快2个月了,年头年尾总是比较忙哈,在React 入门教程(一)我大概介绍了 React 的使用和一些注意事项,这次让我们来继续学习 React 一. Rea ...