Educational Codeforces Round 20 A. Maximal Binary Matrix
1 second
256 megabytes
standard input
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.
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就可以填两个数的,先填主对角线啊填的过程中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的更多相关文章
- 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
Educational Codeforces Round 20 A. Maximal Binary Matrix 直接从上到下从左到右填,注意只剩一个要填的位置的情况 view code //#pr ...
- Educational Codeforces Round 20 A
Description You are given matrix with n rows and n columns filled with zeroes. You should put k ones ...
- 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
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(math)
題目鏈接: http://codeforces.com/problemset/problem/803/C 題意: 給出兩個數n, k, 將n拆分成k個數的和,要求這k個數是嚴格遞增的,並且這k個數的g ...
- 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 E - Roma and Poker(dp)
传送门 题意 Roma在玩一个游戏,一共玩了n局,赢则bourle+1,输则bourle-1,Roma将会在以下情况中退出 1.他赢了k个bourle 2.他输了k个bourle 现在给出一个字符串 ...
随机推荐
- 洛谷 P2598 [ZJOI2009]狼和羊的故事
题目描述 “狼爱上羊啊爱的疯狂,谁让他们真爱了一场:狼爱上羊啊并不荒唐,他们说有爱就有方向......” Orez听到这首歌,心想:狼和羊如此和谐,为什么不尝试羊狼合养呢?说干就干! Orez的羊狼圈 ...
- A winner is a dreamer who never gives up
A winner is a dreamer who never gives up. 成功者是坚持梦想不放弃的人.(Nelson Mandela)
- UVA 1149 Bin Packing 装箱(贪心)
每次选最大的物品和最小的物品放一起,如果放不下,大物体孤独终生,否则相伴而行... 答案变得更优是因为两个物品一起放了,最大的物品是最难匹配的,如果和最小的都放不下的话,和其它匹配也一定放不下了. # ...
- CDOJ 490 UESTC 490 Swap Game(思路,逆序对)
题意:有两种颜色的小球形成环,求最小交互次数使球相连. 题解:先解决另一个简单的问题,如果是一个链,把红球标记为1,蓝球标记为0,要排成升序需要多少次交换呢?答案是逆序对总数,原因是一次交互最多消除一 ...
- 字符串的驻留(String Interning)
http://www.cnblogs.com/artech/archive/2007/03/04/663728.html 关于字符串的驻留的机制,对于那些了解它的人肯定会认为很简单,但是我相信会有很大 ...
- 01_6_Struts_ActionWildcard_通配符配置
01_6_Struts_ActionWildcard_通配符配置 1.Struts_ActionWildcard_通配符配置 1.1配置struts.xml文件 <package name=&q ...
- 01_2_Servlet简介
01_2_Servlet简介 1. Servlet简介 Servlet是服务器小应用程序 用来完成B/S架构下,客户端请求的响应处理 平台独立,性能优良,能以线程方式运行 Servlet API为Se ...
- nodejs写一个简单的Web服务器
目录文件如 httpFile.js如下: const httpd = require("http"); const fs = require("fs"); // ...
- 微信小程序传值取值的几种方法
一,列表index下的取值 实现方式是:data-index="{{index}}"挖坑及e.currentTarget.dataset.index来填坑即可 1.1生成值 < ...
- JS数据结构与算法--单向链表
链表结构:链表中每个元素由一个存储元素本身的节点和一个指向下一元素的引用组成.如下所示(手画的,比较丑,懒得用工具画了,嘻嘻) 1.append方法,向链表末尾插入一个节点 2.insert(posi ...