Codeforces 625C K-special Tables 【贪心】
来源:互联网 发布:北欧象征 知乎 编辑:程序博客网 时间:2024/05/29 10:23
题意:让你用1-n*n这些数填充n*n矩阵,要求每行的数字严格递增、每个数字只能用一次且保证第k列的数字和最大。
思路:贪心选数,随便搞搞就过了。
AC代码:
#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <cstdlib>#include <algorithm>#include <queue>#include <stack>#include <map>#include <set>#include <vector>#include <string>#define INF 1000000#define eps 1e-8#define MAXN (100000+10)#define MAXM (10000+10)#define Ri(a) scanf("%d", &a)#define Rl(a) scanf("%lld", &a)#define Rf(a) scanf("%lf", &a)#define Rs(a) scanf("%s", a)#define Pi(a) printf("%d\n", (a))#define Pf(a) printf("%.2lf\n", (a))#define Pl(a) printf("%lld\n", (a))#define Ps(a) printf("%s\n", (a))#define W(a) while((a)--)#define CLR(a, b) memset(a, (b), sizeof(a))#define MOD 1000000007#define LL long long#define lson o<<1, l, mid#define rson o<<1|1, mid+1, r#define ll o<<1#define rr o<<1|1#define PI acos(-1.0)#pragma comment(linker, "/STACK:102400000,102400000")#define fi first#define se secondusing namespace std;typedef pair<int, int> pii;int Map[600][600];int main(){ int n, k; Ri(n); Ri(k); int Max = n * n; int Min = 1; for(int i = 1; i <= n; i++) { Max -= (n - k); Map[i][k] = Max; for(int j = k+1; j <= n; j++) Map[i][j] = Map[i][j-1] + 1; for(int j = 1; j < k; j++) Map[i][j] = Min++; Max--; } int sum = 0; for(int i = 1; i <= n; i++) sum += Map[i][k]; Pi(sum); for(int i = 1; i <= n; i++) { for(int j = 1; j <= n; j++) { if(j > 1) printf(" "); printf("%d", Map[i][j]); } printf("\n"); } return 0;}
0 0
- Codeforces 625C K-special Tables 【贪心】
- CodeForces 625C K-special Tables
- Codeforces 625C - K-special Tables
- CodeFOrces 625C - K-special Tables
- 【77.78%】【codeforces 625C】K-special Tables
- CodeForces 625 C. K-special Tables(水~)
- CF#342(2) C. K-special Tables 贪心
- Codeforces Round #342 (Div. 2)--C. K-special Tables
- Codeforces Round #342 (Div. 2) 625C K-special Tables(脑洞)
- cf 625 C. K-special Tables (打表+规律)
- cf#342-C - K-special Tables-构造
- C. K-special Tables【构造】水
- Codeforces Round #342 (Div. 2)-C. K-special Tables(模拟)
- coderforces342C. K-special Tables
- CodeForces 275C 贪心
- codeforces C. Bits 贪心
- codeforces C. Hometask(贪心)
- Codeforces 449C 贪心
- 《笨办法学Python》 第35课手记
- 吐槽我是特种兵之霹雳火
- hdoj1540Tunnel Warfare【线段树】
- Codeforces 625A Guest From the Past 【基础数学】
- Codeforces 625B War of the Corporations 【暴力】
- Codeforces 625C K-special Tables 【贪心】
- 快速幂&快速乘
- 在amazon ec2上部署spark cluster
- DP之状态和状态转移
- YTU 2620: B 链表操作
- 获取通讯录(AddressBookUI框架)
- linux 文件及目录
- YTU 2621: B 继承 圆到圆柱体
- 125天记录