Educational Codeforces Round 20 A
Description
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.
The first line consists of two numbers n and k (1 ≤ n ≤ 100, 0 ≤ k ≤ 106).
If the answer exists then output resulting matrix. Otherwise output -1.
2 1
1 0
0 0
3 2
1 0 0
0 1 0
0 0 0
2 5
-1
题意:问如何将二进制矩阵排成字典序最大(需要主对角线对称)
解法:当然是这种啦,如果发现还有剩余1就输出-1
1 1 1 1 1 1 1 1 1...
1 1
1 1
1 .
1 .
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn=;
int x[][];
int n;
int num;
int main()
{
cin>>n>>num;
for(int i=;num>&&i<=n;i++)
{
x[i][i]=;
num--;
for(int j=i+;num>&&j<=n;j++)
{
x[i][j]=x[j][i]=;
num-=;
}
}
if(num>)
{
cout<<"-1"<<endl;
return ;
}
for(int i=;i<=n;i++)
{
for(int j=;j<=n;j++)
{
cout<<x[i][j]<<" ";
}
cout<<endl;
}
return ;
}
Educational Codeforces Round 20 A的更多相关文章
- Educational Codeforces Round 20
Educational Codeforces Round 20 A. Maximal Binary Matrix 直接从上到下从左到右填,注意只剩一个要填的位置的情况 view code //#pr ...
- 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 ...
- Educational Codeforces Round 20 C(math)
題目鏈接: http://codeforces.com/problemset/problem/803/C 題意: 給出兩個數n, k, 將n拆分成k個數的和,要求這k個數是嚴格遞增的,並且這k個數的g ...
- Educational Codeforces Round 20.C
C. Maximal GCD time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- Educational Codeforces Round 20 C 数学/贪心/构造
C. Maximal GCD time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- 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 ...
- 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 ...
- 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 ...
- Educational Codeforces Round 20 E - Roma and Poker(dp)
传送门 题意 Roma在玩一个游戏,一共玩了n局,赢则bourle+1,输则bourle-1,Roma将会在以下情况中退出 1.他赢了k个bourle 2.他输了k个bourle 现在给出一个字符串 ...
- Educational Codeforces Round 20 B
Description You are given the array of integer numbers a0, a1, ..., an - 1. For each element find th ...
随机推荐
- linux 标准i2c接口(一)
一:I2C设备操作方式: 1. 应用程序操作法:i2c的设备的驱动可以直接利用linux内核提供的i2c-dev.c文件提供的ioctl函数接口在应用层实现对i2c设备的读写,但是在应用层使用ioc ...
- C++类中使用new及delete小例子(续)
在该示例中我们显式定义了复制构造函数来代替默认复制构造函数, 在该复制构造函数的函数体内, 不是再直接将源对象所申请空间的地址赋值给被初始化的对象, 而是自己独立申请一处内存后再将源对象的属性复制过来 ...
- HTML页面中点击按钮关闭页面几种方式与取消
1.不带任何提示关闭窗口的js代码 <input type="button" name="close" value="关闭" oncl ...
- Fairy Tail - Main Theme Slow Version guitar (solo)
Хвост Феи animelodies1 (on youtube) Переписал jarrro (on vk.com)
- Vs2012在Linux开发中的应用(6):改写Makefile项目的Build过程
MSBUILD的编译过程实际上是依据一系列的targets文件定义的.当我们在IDE运行生成.批生成.清理命令的时候.VS会查找这些命令相应的Task并运行它,以下我们逐个分析这个过程. 当运行生成操 ...
- php composer 相关及版本约束等小技巧
对于现代语言而言,包管理器基本上是标配.Java有Maven,Python有pip,Ruby有gem,Nodejs有npm.PHP的则是PEAR,不过PEAR坑不少: 依赖处理容易出问题 配置非常复杂 ...
- @SpringBootApplication 注解
@SpringBootApplication 启动类注解(一般在root下):该注解被@Configuration.@EnableAutoConfiguration.@ComponentScan 这三 ...
- android提权漏洞CVE-2010-EASY修复【转】
本文转载自: http://blog.csdn.net/lhj0711010212/article/details/9351131 android提权漏洞CVE-2010-EASY修复 linux ...
- SpringBoot配置文件详解
自定义属性与加载 com.dongk.selfproperty.title=wangdkcom.dongk.selfproperty.name=10000 然后通过@Value("${属性名 ...
- Oracle:热备测试
我们知道Oracle数据库热备有3步: 1. alter tablespace tbname begin backup: 2. cp /××× to /×× 3. alter ta ...