codeforces 625C K-special Tables
2 seconds
256 megabytes
standard input
standard output
People do many crazy things to stand out in a crowd. Some of them dance, some learn by heart rules of Russian language, some try to become an outstanding competitive programmers, while others collect funny math objects.
Alis is among these collectors. Right now she wants to get one of k-special tables. In case you forget, the table n × n is calledk-special if the following three conditions are satisfied:
- every integer from 1 to n2 appears in the table exactly once;
- in each row numbers are situated in increasing order;
- the sum of numbers in the k-th column is maximum possible.
Your goal is to help Alice and find at least one k-special table of size n × n. Both rows and columns are numbered from 1 to n, with rows numbered from top to bottom and columns numbered from left to right.
The first line of the input contains two integers n and k (1 ≤ n ≤ 500, 1 ≤ k ≤ n) — the size of the table Alice is looking for and the column that should have maximum possible sum.
First print the sum of the integers in the k-th column of the required table.
Next n lines should contain the description of the table itself: first line should contains n elements of the first row, second line should contain n elements of the second row and so on.
If there are multiple suitable table, you are allowed to print any.
4 1
28
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
5 3
85
5 6 17 18 19
9 10 23 24 25
7 8 20 21 22
3 4 14 15 16
1 2 11 12 13 题意:给两个数n,k,要求输出一个n*n的矩阵,要求1、其中的数是1到n*n 要求2、输出的每一行严格递增,要求3、在满足前两个条件的情况下第k列的和最大 题解:我们只需要找出第k列的数的值即可得出整个矩阵的值,
#include<stdio.h>
#include<string.h>
#include<string>
#include<math.h>
#include<algorithm>
#define LL long long
#define PI atan(1.0)*4
#define DD double
#define MAX 510
#define mod 100
#define dian 1.000000011
#define INF 0x3f3f3f
int s[MAX];
int map[MAX][MAX];
using namespace std;
int main()
{
int n,m,j,i,k;
int a,b,c,d,o;
while(scanf("%d%d",&n,&k)!=EOF)
{
//ans=n*n;
memset(s,0,sizeof(s));
memset(map,0,sizeof(map));
a=n*(k-1);//从第k列往后最小的数的值
b=a+1;//比b大的数都是第k列之后的数
c=n-k+1;//k列之后还有c列(包括第k列)
int sum=0;
for(i=1;i<=n;i++)
{
s[i]=b+(i-1)*c;//第k列的值
sum+=s[i];
}
d=b-1;//第k列前边的数中的最大数
o=d/n;
int num=1;
for(i=1;i<=n;i++)
{
for(j=1;j<=o;j++)
map[i][j]=num++;
}
for(i=1;i<=n;i++)
{
int p=0;
for(j=o+1;j<=n;j++)
map[i][j]=s[i]+p++;
}
printf("%d\n",sum);
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
printf("%d ",map[i][j]);
printf("\n");
}
}
return 0;
}
codeforces 625C K-special Tables的更多相关文章
- 【77.78%】【codeforces 625C】K-special Tables
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...
- 【CodeForces 625C】K-special Tables
题意 把1到n*n填在n*n的格子里.要求每一行都是递增的,使第k列的和最大. 分析 第k列前的格子1 2 .. 按要求填到满格,然后第k列及后面的格子,都从左到右填递增1的数. 第k列的和再加起来, ...
- Codeforces gym102152 K.Subarrays OR
传送:http://codeforces.com/gym/102152/problem/K 题意:给定$n(n\le10^5)$个数$a_i(a_i\le10^9)$,对于任一个子数组中的数进行或操作 ...
- codeforces 1133E K Balanced Teams
题目链接:http://codeforces.com/contest/1133/problem/E 题目大意: 在n个人中找到k个队伍.每个队伍必须满足最大值减最小值不超过5.求满足条件k个队伍人数的 ...
- Codeforces 1133E - K Balanced Teams - [DP]
题目链接:https://codeforces.com/contest/1133/problem/C 题意: 给出 $n$ 个数,选取其中若干个数分别组成 $k$ 组,要求每组内最大值与最小值的差值不 ...
- codeforces 1269E K Integers (二分+树状数组)
链接:https://codeforces.com/contest/1269/problem/E 题意:给一个序列P1,P2,P3,P4....Pi,每次可以交换两个相邻的元素,执行最小次数的交换移动 ...
- codeforces 1282B2. K for the Price of One (Hard Version) (dp)
链接 https://codeforces.com/contest/1282/problem/B2 题意: 商店买东西,商店有n个物品,每个物品有自己的价格,商店有个优惠活动,当你买恰好k个东西时可以 ...
- Codeforces 544E K Balanced Teams (DP)
题目: You are a coach at your local university. There are nn students under your supervision, the prog ...
- Codeforces Gym101502 K.Malek and Summer Semester
K. Malek and Summer Semester time limit per test 1.0 s memory limit per test 256 MB input standard ...
随机推荐
- git push 提示
我运行git push -u origin master 时提示如下: To git@github.com:userName/project.git ! [rejected] master -> ...
- HDU 4946 共线凸包
题目大意: 一些点在一张无穷图上面,每个点可以控制一些区域,这个区域满足这个点到达这个区域的时间严格小于其他点.求哪些点能够控制无穷面积的区域. 题目思路: 速度小的控制范围一定有限. 速度最大当且仅 ...
- iOS开发:记录开发中遇到的编译或运行异常以及解决方案
1.部署到真机异常 dyld`dyld_fatal_error: -> 0x120015088 <+0>: brk #0x3 dyld: Library not loaded ...
- bzoj1601: [Usaco2008 Oct]灌水
经典延伸最小生成树问题... #include<cstdio> #include<cstring> #include<cctype> #include<alg ...
- Jqgrid入门-别具特色的Pager Bar (四)
Pager Bar位于表格最下边.默认情况下,分为三部分.如图: 第一部分:导航按钮栏(Navigator) 第二部分:页码栏(Pager) 第三部分:记录信息栏(Record) 要实 ...
- 原创: 做一款属于自己风格的音乐播放器 (HTML5的Audio新特性)
灵感的由来是前些天看到了博: http://www.cnblogs.com/li-cheng 的首页有一个很漂亮的播放器,感觉很不错,是用Flex做的Flash播放器. 于是我也便想到了,自己也来来弄 ...
- apache开源项目 --Struts
struts简介 Struts是Apache软件基金会(ASF)赞助的一个开源项目.它最初是jakarta项目中的一个子项目,并在2004年3月成为ASF的顶级项目.它通过采用JavaServlet/ ...
- jQuery live与bind的区别
平时在使用jQuery进行AJAX操作的时候,新生成的元素事件会失效,有时候不得不重新绑定一下事件,但是这样做很麻烦.例如评论分页后对评论内容的JS验证会失效等.在jQuery1.3之前有一个插件会解 ...
- Ruby网络服务
#require 'net/http' #p Net::HTTP.get_response(URI.parse('http://www.kuaiyoujia.com')){|res| # puts r ...
- MySQL基础之第6章 创建、修改和删除表 .
6.1.创建表 6.1.1.创建表的语法形式 CREATE TABLE 表名 ( 属性名 数据类型 [完整性约束条件],属性名 数据类型 [完整性约束条件],...... 属性名 数据类型); 完整性 ...