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 现在给出一个字符串 ...
随机推荐
- Python+selenium之Page Object设计模式
Page Object是selenium自动化测试项目开发实践的最佳设计模式之一,他主要提现在对界面交互细节的封装,这样可以使测试案例隔你给加关注于业务而非界面细节,从而提高测试案例的可读性. Pag ...
- mongodb安全整理
本文大都网上参考的,我只是整理了一下 一默认配置情况 1.MongoDB安装时不添加任何参数,默认是没有权限验证的,任何用户都可以登录进来,而且登录的用户可以对数据库任意操作而且可以远程访问数据库,需 ...
- python基础一 day15 面试题
# def demo():# for i in range(4):# yield i## g=demo()## g1=(i for i in g)# g2=(i for i in g1)## prin ...
- PAT (Basic Level) Practise (中文)- 1010. 一元多项式求导 (25)
http://www.patest.cn/contests/pat-b-practise/1010 设计函数求一元多项式的导数.(注:xn(n为整数)的一阶导数为n*xn-1.) 输入格式:以指数递降 ...
- 基于GPS\北斗、GIS、GPRS技术构建智能巡检系统
巡线工负责输油管网设施的日常巡查,可以及时发现管网设施是否完好.但巡检工作辛苦,加之管线在大部分情况下又处于良好状态,使得巡检人员麻痹大意,往往不能按规定程序进行巡检,造成巡检不到位,这样就不能从根本 ...
- ReactiveCocoa入门-part1
作为一个iOS开发者,你写的每一行代码几乎都是在响应某个事件,例如按钮的点击,收到网络消息,属性的变化(通过KVO)或者用户位置的变化(通过CoreLocation).但是这些事件都用不同的方式来处理 ...
- NSRegularExpression 使用
需求: // 后台返回的某个实体 reminder = { cost = , type = , template = 可免费做某事{time}分钟,超过将按{cost}K元收费, time = } t ...
- 使用js将div高度设置为100%
在开发的工程中使用到了一些开源的bootstrap模板进行开发,在遇到一些需要替换的内容部分部分时,经常出现高度设置100%无法生效的问题,这里来用js强行设置一下. 思路:js监听窗口的缩放 ...
- jquery.imgpreload.min.js插件实现页面图片预加载
页面分享地址: http://wenku.baidu.com/link?url=_-G8miwbgDmEj6miyFtjit1duJggBCJmFjR2jky_G1VftD9eS9kwGOlFWAOR ...
- python3中urllib库的request模块详解
刚刚接触爬虫,基础的东西得时时回顾才行,这么全面的帖子无论如何也得厚着脸皮转过来啊! 原帖地址:https://www.2cto.com/kf/201801/714859.html 什么是 Urlli ...