【CodeForces 625C】K-special Tables
Codeforces tables special
2023-09-11 14:19:25 时间
题意
把1到n*n填在n*n的格子里。要求每一行都是递增的,使第k列的和最大。
分析
第k列前的格子1 2 .. 按要求填到满格,然后第k列及后面的格子,都从左到右填递增1的数。
第k列的和再加起来,我很矫情地求了公式=_=
代码
#include<cstdio> int n,k; int a[505][505]; int main() { scanf("%d%d",&n,&k); int m=1; for(int i=1; i<=n; i++) for(int j=1; j<k; j++) { a[i][j]=m++; } for(int i=1; i<=n; i++) for(int j=k; j<=n; j++) { a[i][j]=m++; } printf("%d\n",(n*(n-2+k)+k+1)*n/2); for(int i=1; i<=n; i++) { for(int j=1; j<=n; j++) { printf("%d ",a[i][j]); } printf("\n"); } return 0; }
相关文章
- 【Codeforces Round #696 (Div. 2) C】Array Destruction
- 【Codeforces Round #695 (Div. 2) A】Wizard of Orz
- 【Codeforces 478C】Table Decorations
- 【Codeforces Round #505 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final) A】 Doggo Recoloring
- 【Codeforces Round #455 (Div. 2) C】 Python Indentation
- 【codeforces 767B】The Queue
- 【codeforces 534A】Exam
- 【codeforces 779A】Pupils Redistribution
- 【codeforces 798B】Mike and strings
- 【Codeforces Round #431 (Div. 2) C】From Y to Y
- 【Codeforces Round #427 (Div. 2) A】Key races
- 【codeforces 496E】Distributing Parts
- 【codeforces 553C】Love Triangles
- 【codeforces 799A】Carrot Cakes
- 【codeforces 803E】Roma and Poker
- Codeforces Round #254 (Div. 2)D(预计)
- Codeforces Round #273 (Div. 2)
- Codeforces 390E Inna and Large Sweet Matrix 树状数组改段求段
- Codecraft-18 and Codeforces Round #458 (Div. 1 + Div. 2, combined)
- Codeforces Round #411 (Div. 2)