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. Ruby菜鸟入门指南

    写这篇文章的初衷源于我的伙伴们在上手Ruby过程中,表现实在是太让人拙计了.由于项目的急功近利,需要迅速入门Ruby并上手项目.所以很多开发者在实际开发过程中,不熟悉Ruby的表达方式,也会沿用其他语 ...

  2. HDU 2639 Bone Collector II (01背包,第k解)

    题意: 数据是常规的01背包,但是求的不是最大容量限制下的最佳解,而是第k佳解. 思路: 有两种解法: 1)网上普遍用的O(V*K*N). 2)先用常规01背包的方法求出背包容量限制下能装的最大价值m ...

  3. HTML_4

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...

  4. python之golbal/nonlocal

    一.关键字 golbal nonlocal 在局部修改全局的变量为什么会报错 count = 0 def func(): count += 1 func() # UnboundLocalError: ...

  5. 如何将字符串@“ abc123.xyz789”倒置

    #import <Foundation/Foundation.h> int main(int argc, const char * argv[]) { @autoreleasepool { ...

  6. MySQL数据库的多种备份与多种还原

    一.备份 1.mysqldump 方法备份 mysqldump备份很简单,格式如下: mysqldump -u用户名 -p密码 数据库名> XX.sql 路径 例如: mysqldump -ur ...

  7. 【windows】【md5】查看文件的md5值

    certutil -hashfile filename MD5 certutil -hashfile filename SHA1 certutil -hashfile filename SHA256 ...

  8. [译]The Python Tutorial#8. Errors and Exceptions

    [译]The Python Tutorial#Errors and Exceptions 到现在为止都没有过多介绍错误信息,但是已经在一些示例中使用过错误信息.Python至少有两种类型的错误:语法错 ...

  9. poj-2488 a knight's journey(搜索题)

    Time limit1000 ms Memory limit65536 kB Background The knight is getting bored of seeing the same bla ...

  10. 使用docker+tomcat部署jenkins