CodeForces - 361A-Levko and Table (思维)
Levko loves tables that consist of n rows and n columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals k.
Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them.
Input
The single line contains two integers, n and k (1 ≤ n ≤ 100, 1 ≤ k ≤ 1000).
Output
Print any beautiful table. Levko doesn't like too big numbers, so all elements of the table mustn't exceed 1000 in their absolute value.
If there are multiple suitable tables, you are allowed to print any of them.
Examples
Input
2 4
Output
1 3
3 1
Input
4 7
Output
2 1 0 4
4 0 2 1
1 3 3 0
0 3 2 2
Note
In the first sample the sum in the first row is 1 + 3 = 4, in the second row — 3 + 1 = 4, in the first column — 1 + 3 = 4 and in the second column — 3 + 1 = 4. There are other beautiful tables for this sample.
In the second sample the sum of elements in each row and each column equals 7. Besides, there are other tables that meet the statement requirements.
题解:这道题我最初的想法是用深搜来做,但是感觉放在第一题的位置肯定大材小用,然后不难发现只要输出任意符合要求的一组即可,只需要对角线是k即可
代码:
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
int a[105][105];
int main() {
int n,k;
cin>>n>>k;
for(int t=0; t<n; t++) {
for(int j=0; j<n; j++) {
if(t==j) {
a[t][j]=k;
}
}
}
for(int t=0; t<n; t++) {
for(int j=0; j<n; j++) {
cout<<a[t][j]<<" ";
}
cout<<endl;
}
return 0;
}
CodeForces - 361A-Levko and Table (思维)的更多相关文章
- codeforces 245 D. Restoring Table(位运算+思维)
题目链接:http://codeforces.com/contest/245/problem/D 题意:给出一个矩阵b,b[i][j]=a[i]&a[j],b[i][i]=-1.然后求a[i] ...
- Codeforces Round #210 (Div. 2) A. Levko and Table
让对角线的元素为k就行 #include <iostream> using namespace std; int main() { int n,k; cin >> n > ...
- Codeforces 1012B Chemical table (思维+二分图)
<题目链接> 题目大意:给定一个n*m的矩阵网格,向其中加点,对于一个组成矩形的四个点中如果有三个点中有元素,那么第四个点中会自动产生新的元素.问你最少再加多少个点能够填满这个网格.解题分 ...
- codeforces B. Levko and Permutation 解题报告
题目链接:http://codeforces.com/problemset/problem/361/B 题目意思:有n个数,这些数的范围是[1,n],并且每个数都是不相同的.你需要构造一个排列,使得这 ...
- CodeForces - 427A (警察和罪犯 思维题)
Police Recruits Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u Sub ...
- Codeforces 448 D. Multiplication Table
二分法判断答案 D. Multiplication Table time limit per test 1 second memory limit per test 256 megabytes inp ...
- codeforces 895B XK Segments 二分 思维
codeforces 895B XK Segments 题目大意: 寻找符合要求的\((i,j)\)对,有:\[a_i \le a_j \] 同时存在\(k\),且\(k\)能够被\(x\)整除,\( ...
- codeforces 893D Credit Card 贪心 思维
codeforces 893D Credit Card 题目大意: 有一张信用卡可以使用,每天白天都可以去给卡充钱.到了晚上,进入银行对卡的操作时间,操作有三种: 1.\(a_i>0\) 银行会 ...
- Codeforces 448 D. Multiplication Table 二分
题目链接:D. Multiplication Table 题意: 给出N×M的乘法矩阵要你求在这个惩罚矩阵中第k个小的元素(1 ≤ n, m ≤ 5·10^5; 1 ≤ k ≤ n·m). 题解: n ...
- C. Nice Garland Codeforces Round #535 (Div. 3) 思维题
C. Nice Garland time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...
随机推荐
- BZOJ 1651 [Usaco2006 Feb]Stall Reservations 专用牛棚:优先队列【线段最大重叠层数】
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1651 题意: 给你n个线段[a,b],问你这些线段重叠最多的地方有几层. 题解: 先将线段 ...
- frp支持httpIP地址加端口号访问
(一)安装就不再多说 传送门:https://blog.csdn.net/superljn/article/details/81289993 (二)vim frps.ini [common] bind ...
- int型变量,不使用中间变量完成互换
package com.t_02; /** * 定义两个int类型的数,完成交换,不使用第三方变量 * @author Administrator * */ public class t1 { pub ...
- 【HDU 4807】Lunch Time 最小费用最大流
题意 在一个有向图当中,现在每一条边带有一个容量,现在有K个人在起点,需要到终点去吃饭,询问这K个人最后一个人到达食堂的最小时间是多少 贴一篇题解:http://blog.csdn.net/u0137 ...
- 解决按 backspace键 出现 ^H 问题
输入命令 stty erase ^H #stty 时一个用来改变并打印终端行设置的常用命令stty iuclc # 在命令行下禁止输出大写stty -iuclc ...
- DataGridColum的bug
Datagrid有多个bug: 1,不支持DynamicResource的东西 2, 在Column隐藏后再显示, ColumnHeader的Tag或者DataContext为null. 解决办法: ...
- java对世界各个时区(TimeZone)的通用转换处理方法
在进行国际性软件项目开发的过程中,有时候会碰到一些比较特殊的要求.比如:比如说,你做的是个购物网站(假设服务器放在中国上海),当全世界客户在你的网站上下订单买东西后,往往希望看到客户所在地下单时间,比 ...
- POJ1523(割点所确定的连用分量数目,tarjan算法原理理解)
SPF Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 7406 Accepted: 3363 Description C ...
- Oracle的case 用法
1.测试表declare @stuinfo table(id int, sname nvarchar(20), ///小组名称 gender varchar(1), //小组性别 sgroup int ...
- shader之顶点着色器
Vertex Shader 是渲染管道中一个可编程的模块,用于处理独立的顶点.Vertex Shader接收Vertex Attribute Data,由定点数组对象通过渲染指令来生成. Vertex ...