Educational Codeforces Round 20 a Maximal Binary Matrix

原创 2018年04月17日 17:06:03

题目链接:http://codeforces.com/contest/803/problem/A

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
Copy
2 1
Output
Copy
1 0 
0 0 
Input
Copy
3 2
Output
Copy
1 0 0 
0 1 0 
0 0 0 
Input
Copy
2 5
Output
Copy
-1

题面大意:给你一个n阶矩阵,初始化为0,然后让你填入k个1.要求填充之后的矩阵对称,并且从上到下,从左到右的字典序是最大的

思路:

开始判断k与n^2的关系。大于n^2,输出-1.否则二重循环扫描,每到一个点,判断是否为对角线上的点,如果是,那么填充计数器cnt+1,不过不是cnt+2,同时判断此时cnt与k的大小,比k大。那就将下一行的对角线上的元素变为1.然后输出矩阵
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#define ll long long
using namespace std;
int g[105][105];
int main()
{
    int n,k;
   cin>>n>>k;
   int cnt=1;
   if(k>n*n)
    cout<<-1<<endl;
    else
    {
       for(int i=0;i<n;i++)
       {
           for(int j=i;j<n;j++)
           {
               if(cnt>k)
               {
                   break;
               }
               else
               {
                   if(i==j)
                  {

                     g[i][j]=1;
                     cnt++;
                  }
                  else
                  {
                     // cout<<cnt<<endl;
                   if(cnt+1<=k)
                   {
                       g[i][j]=1;
                       g[j][i]=1;
                       cnt+=2;
                   }
                   else
                   {
                       g[i+1][i+1]=1;
                       cnt++;
                   }
                  }
               }

           }
       }
       for(int i=0;i<n;i++)
       {
           for(int j=0;j<n;j++)
           {
               cout<<g[i][j]<<' ';
           }
           cout<<endl;
       }
    }
    return 0;
}

Codeforces Educational 38 C. Constructing Tests ( 构造

题目描述 Let’s denote a m-free matrix as a binary (that is, consisting of only 1’s and 0’s) matrix such...
  • wang2332
  • wang2332
  • 2018-02-18 03:29:17
  • 164

【解题报告】 Educational Codeforces Round 40

题目链接 A. Diagonal Walking(Codeforces 954A) 题意 给出一个仅含RRR和UUU的字符串。问如何进行一系列操作(每次操作可以将连续的RURURU或...
  • TRiddle
  • TRiddle
  • 2018-03-24 01:34:18
  • 112

Educational Codeforces Round 40 (Rated for Div. 2)

Educational Codeforces Round 40 (Rated for Div. 2) 比赛地址 A. Diagonal Walking time limit per te...
  • wordsin
  • wordsin
  • 2018-03-22 20:11:59
  • 43

Educational Codeforces Round 38 C. Constructing Tests 思维

C. Constructing Teststime limit per test1 secondmemory limit per test256 megabytesinputstandard inpu...
  • Frost_Bite
  • Frost_Bite
  • 2018-02-21 22:23:28
  • 78

Educational Codeforces Round 41 (Rated for Div. 2)

A:找出现次数最少的 B:贪心,寻找长度为k区间的,标记0的最大和,预处理下标记为0的前缀和 C:对于四块板子,可行的方案中. 1/3板子一样,2/4板子一样,并且有2种方案 1...
  • Haipai1998
  • Haipai1998
  • 2018-04-05 10:33:41
  • 61

解题报告: Educational Codeforces Round 24 A,B,C

A、题目链接 题意: n个人,有人有文凭,有人有证书,有的人什么也没有,其中有证书的人数量为有文凭的人的k倍,我们称有文凭或者有证书的人为有奖状的人,已知有奖的人不超过一半,询问最多有多少人获奖。...
  • qq_32570675
  • qq_32570675
  • 2017-07-01 11:26:35
  • 232

Educational Codeforces Round 20 Maximal Binary Matrix

A. Maximal Binary Matrix time limit per test 1 second memory limit per test 256 megabyte...
  • qq_30591245
  • qq_30591245
  • 2017-04-29 12:51:24
  • 99

Educational Codeforces Round 36

比赛链接 小号打了一场E round,被连hack两道= = A. Garden 题意: 给n个数和一个m,问n个数中能整除m的并且商最小的那个商是多少。 做法: 傻逼题。 ...
  • bestFy
  • bestFy
  • 2018-01-16 12:45:18
  • 114

Educational Codeforces Round 38 (Rated for Div. 2) B. Run For Your Prize

B. Run For Your PrizeYou and your friend are participating in a TV show &quot;Run For Your Prize&quo...
  • s540239976
  • s540239976
  • 2018-02-17 13:35:37
  • 213

Educational Codeforces Round 38 (Rated for Div. 2) A. Word Correction

A. Word CorrectionVictor tries to write his own text editor, with word correction included. However,...
  • s540239976
  • s540239976
  • 2018-02-17 13:22:42
  • 133
收藏助手
不良信息举报
您举报文章:Educational Codeforces Round 20 a Maximal Binary Matrix
举报原因:
原因补充:

(最多只允许输入30个字)