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 ...
随机推荐
- C#6.0 VS2015
https://msdn.microsoft.com/en-us/library/hh156499(v=vs.140).aspx This page lists key feature names f ...
- MyBatis学习总结3-优化MyBatis配置文件
连接数据库配置优化 可以将数据库连接配置信息卸载conf.xml中,但是为了优化连接,专门写一个properties用于存数据库连接信息,然后在conf.xml中进行引用,里面包括数据库驱动,地址,用 ...
- ACM - ICPC World Finals 2013 D Factors
原题下载:http://icpc.baylor.edu/download/worldfinals/problems/icpc2013.pdf 题目翻译: 问题描述 一个最基本的算数法则就是大于1的整数 ...
- GET,POST,PUT,DELETE的区别
Http定义了与服务器交互的不同方法,最基本的方法有4种,分别是GET,POST,PUT,DELETE.URL全称是资源描述符,我们可以这样认为:一个URL地址,它用于描述一个网络上的资源,而HTTP ...
- sql Server 的基本函数
--聚合函数 use pubs go select avg(distinct搜索 price) --算平均数 from titles where type='business' go use pubs ...
- POJ 3084 Panic Room (最小割建模)
[题意]理解了半天--大意就是,有一些房间,初始时某些房间之间有一些门,并且这些门是打开的,也就是可以来回走动的,但是这些门是确切属于某个房间的,也就是说如果要锁门,则只有在那个房间里才能锁. 现在一 ...
- HDU 5296 Annoying problem (LCA,变形)
题意: 给一棵n个节点的树,再给q个操作,初始集合S为空,每个操作要在一个集合S中删除或增加某些点,输出每次操作后:要使得集合中任意两点互可达所耗最小需要多少权值.(记住只能利用原来给的树边.给的树边 ...
- 利用改进的cca算法,进行识别
这个方法,很有意思,第一,不用降维:第二,跟ica做比较,竟然说比强大的ica还好: 看来,国防科大的博士,还是很牛的. <OI and fMRI Signal Separation Using ...
- BUFFER CACHE之主要的等待事件
原因:资源紧张,等待其释放. 原因的原因:1. lgwr和DBWn进程写太慢:2. Buffer和latch不可用 原因的原因的原因:全表扫描.library cache latches数太多等. 视 ...
- 【Unity3D】枪战游戏—弹孔设置
以子弹为原点,发射射线,如果射线检测到障碍物,则返回射线与障碍物的碰撞点 在该点处实例化出弹孔贴图 void Update () { transform.Translate (Vector3.forw ...