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. uvm_reg_predictor——寄存器模型(十一)

    保存寄存器的值 观察DUT寄存器值的变化. //---------------------------------------------------------------------------- ...

  2. elasticsearch查询方式

    1.query string a).GET /index/type/_search ===>>查询所有 b).GET /index/type/_search?q=filed:value&a ...

  3. python3发送邮件02(简单例子,带附件)

    #!/usr/bin/env python# -*- coding:UTF-8 -*- import osimport smtplibfrom email.header import Headerfr ...

  4. COGS 147. [USACO Jan08] 架设电话线

    ★★☆   输入文件:phoneline.in   输出文件:phoneline.out   简单对比时间限制:1 s   内存限制:16 MB Farmer John打算将电话线引到自己的农场,但电 ...

  5. 洛谷 P2905 [USACO08OPEN]农场危机Crisis on the Farm

    题目描述 约翰和他的奶牛组建了一只乐队“后街奶牛”,现在他们正在牧场里排练.奶牛们分成一堆 一堆,共1000)堆.每一堆里,30只奶牛一只踩在另一只的背上,叠成一座牛塔.牧场 里还有M(1 < ...

  6. MVC的验证码

    后台: /// <summary> /// 创建验证码的图片 /// </summary> /// <param name="validateCode" ...

  7. opensuse 15.0 安装ctdb

    问题 1 2019/05/20 15:27:14.574363 ctdb-eventd[26329]: 60.nfs: /etc/ctdb/nfs-linux-kernel-callout: line ...

  8. 解决cocos2dx 3.x 导入cocostudio的ui界面出现错位问题

    笔者今天发现导入cocostudio的ui界面时,会有部分控件出现错位的现象,后来我看了一下源码,发现是部分控件是没有继承 Layout类,导致不能设置控件位置造成,原因可以看看cocos2dx 源码 ...

  9. atomic nonatomic区别

    摘要 atomic和nonatomic区别用来决定编译器生成的getter和setter是否为原子操作.atomic提供多线程安全,是描述该变量是否支持多线程的同步访问,如果选择了atomic 那么就 ...

  10. 20181111 计时器影响DOM点击事件的逻辑

    今天在群里看见一个人在问"点击按钮使图片产生旋转为什么要使用计时器来实现",我自己操作了一遍她的代码才发现里面的逻辑实现很有意思,所以写出来分享一下. 她的代码是这样写的: < ...