分三类
1 1: 一个就好了
3 3:特殊讨论下
n≥4 或 m≥4 : 第一行奇序号的数放前面,偶序号的数放后面,第二行奇序号的数放前面,偶序号的数放后面,第二行依次类推
有点难写,真的菜

#include<iostream>
#include<map>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<set>
#include<vector>
#include<queue>
#include<cmath>
#include<stack>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N = 1e5 + 5;
#define MS(x,y) memset(x,y,sizeof(x))
#define MP(x, y) make_pair(x, y)
const int INF = 0x3f3f3f3f; map<pair<int, int>, int> mp;
int vc[N]; int main() {
int n, m;
while(~scanf("%d %d", &n, &m)) {
mp.clear();
for(int i = 0; i < n; ++i) {
for(int j = 0; j < m; ++j) {
mp[MP(i, j)] = i*m + j;
}
} if(n == 1 && m == 1) {
printf("YES\n1\n");
}else if(n == 3 && m == 3) {
printf("YES\n");
printf("6 1 8\n7 5 3\n2 9 4\n");
}else if(n >= 4) {
printf("YES\n");
for(int i = 0; i < m; ++i) {
int cnt = 0;
for(int j = 0; j < n; ++j) {
vc[cnt ++] = mp[MP(j, i)];
}
if(n == 4) {
if(i & 1) { mp[MP(0, i)] = vc[2]; mp[MP(1, i)] = vc[0]; mp[MP(2, i)] = vc[3]; mp[MP(3, i)] = vc[1]; }
else { mp[MP(0, i)] = vc[1]; mp[MP(1, i)] = vc[3]; mp[MP(2, i)] = vc[0]; mp[MP(3, i)] = vc[2]; }
continue;
}
int tt = 0;
if(i & 1) {
for(int j = 0; j < cnt; j += 2) mp[MP(tt++, i)] = vc[j];
for(int j = 1; j < cnt; j += 2) mp[MP(tt++, i)] = vc[j];
}else {
for(int j = 1; j < cnt; j += 2) mp[MP(tt++, i)] = vc[j];
for(int j = 0; j < cnt; j += 2) mp[MP(tt++, i)] = vc[j]; }
}
for(int i = 0; i < n; ++i) {
for(int j = 0; j < m; ++j) printf("%d ", mp[MP(i, j)] + 1);
printf("\n");
}
}else if(m >= 4) {
printf("YES\n");
for(int i = 0; i < n; ++i) {
int cnt = 0;
for(int j = 0; j < m; ++j) {
vc[cnt ++] = mp[MP(i, j)];
}
if(m == 4) {
if(i & 1) { mp[MP(i, 0)] = vc[2]; mp[MP(i, 1)] = vc[0]; mp[MP(i, 2)] = vc[3]; mp[MP(i, 3)] = vc[1]; }
else { mp[MP(i, 0)] = vc[1]; mp[MP(i, 1)] = vc[3]; mp[MP(i, 2)] = vc[0]; mp[MP(i, 3)] = vc[2]; }
continue;
}
int tt = 0;
if(i & 1) {
for(int j = 0; j < cnt; j += 2) mp[MP(i, tt++)] = vc[j];
for(int j = 1; j < cnt; j += 2) mp[MP(i, tt++)] = vc[j];
}
else {
for(int j = 1; j < cnt; j += 2) mp[MP(i, tt++)] = vc[j];
for(int j = 0; j < cnt; j += 2) mp[MP(i, tt++)] = vc[j];
}
}
for(int i = 0; i < n; ++i) {
for(int j = 0; j < m; ++j) printf("%d ", mp[MP(i, j)] + 1);
printf("\n");
}
}else printf("NO\n");
}
return 0;
}

Codeforces Round #454 D. Seating of Students的更多相关文章

  1. Codeforces Round #454 Div. 1 [ 906A A. Shockers ] [ 906B B. Seating of Students ] [ 906C C. Party ]

    PROBLEM A. Shockers 题 http://codeforces.com/contest/906/problem/A 906A 907C 解 水题,按照题意模拟一下就行了 如果是 ‘ ! ...

  2. Codeforces Round #454

    Masha and Bears Tic-Tac-Toe Shockers Seating of Students Party Power Tower Reverses

  3. Educational Codeforces Round 11 B. Seating On Bus 水题

    B. Seating On Bus 题目连接: http://www.codeforces.com/contest/660/problem/B Description Consider 2n rows ...

  4. Codeforces Round #454 C. Shockers【模拟/hash】

    C. Shockers time limit per test 2 seconds memory limit per test 256 megabytes input standard input o ...

  5. Codeforces Round #454 (Div. 1) CodeForces 906D Power Tower (欧拉降幂)

    题目链接:http://codeforces.com/contest/906/problem/D 题目大意:给定n个整数w[1],w[2],……,w[n],和一个数m,然后有q个询问,每个询问给出一个 ...

  6. Codeforces Round #454 Div. 1

    B:考虑2*m怎么构造.因为要求相邻的数不能再相邻,容易想到黑白染色之类的东西,考虑染个色然后大概把黑点扔一边白点扔一边.显然m<=3时无解.对m>4,m为偶数时,如1 2 3 4 5 6 ...

  7. Codeforces Round #454 Div. 2 A B C (暂时)

    A. Masha and bears 题意 人的体积为\(V\),车的大小为\(size\),人能钻进车的条件是\(V\leq size\),人对车满意的条件是\(2V\geq size\). 现知道 ...

  8. Codeforces Round #454 D. Power Tower (广义欧拉降幂)

    D. Power Tower time limit per test 4.5 seconds memory limit per test 256 megabytes input standard in ...

  9. Codeforces Round #486 (Div. 3) A. Diverse Team

    Codeforces Round #486 (Div. 3) A. Diverse Team 题目连接: http://codeforces.com/contest/988/problem/A Des ...

随机推荐

  1. CF585E. Present for Vitalik the Philatelist [容斥原理 !]

    CF585E. Present for Vitalik the Philatelist 题意:\(n \le 5*10^5\) 数列 \(2 \le a_i \le 10^7\),对于每个数\(a\) ...

  2. 用VS2015编译sqlcipher

    简介 SQLite,是一款轻型的数据库,是遵守ACID的关系型数据库管理系统,它包含在一个相对小的C库中.它是D.RichardHipp建立的公有领域项目.它的设计目标是嵌入式的,而且目前已经在很多嵌 ...

  3. 关于js 全选 反选

    prop 对于HTML元素本身就带有的固有属性,在处理时,使用prop方法. attr  对于HTML元素我们自己自定义的DOM属性,在处理时,使用attr方法. $("#selectAll ...

  4. web前端 ajax请求上传图片数据类型处理

    form: function (url, paras, files, success) {//上传的文件类型是MultipartFile[]//如果把需要的参数直接传入,则会请求错误//设置请求参数的 ...

  5. 处理springMvc中responsebody返回中文乱码

    法一:   @RequestMapping(value="/getUsersByPage",produces = public String getUsers  法二:在sprin ...

  6. TensorFlow实战之实现自编码器过程

    关于本文说明,已同步本人另外一个博客地址位于http://blog.csdn.net/qq_37608890,详见http://blog.csdn.net/qq_37608890/article/de ...

  7. MySQL数据库基础(二)(约束以及修改数据表)

    一,约束以及修改数据表 约束的作用?1.约束保证数据的完整性.一致性:2.约束分为表级约束.列级约束:3.约束类型包括:NOT NULL(非空约束).PRIMARY KEY(主键约束).UNIQUE ...

  8. NoSQL性能测试工具YCSB-Running a Workload

    写在前面 目前,在系统设计中引入了越来越多的NoSQL产品,例如Redis/ MongoDB/ HBase等,其中性能指标往往会成为权衡不同NoSQL产品的关键因素.对这些产品在性能表现和产品选择上的 ...

  9. springmvc+mybatis+mysql 数据库插入中文是乱码

    java web项目,前台页面的表单数据,插入到数据库时,结果出现乱码"???"的问题,断断续续折腾了一天时间,废话不说,步骤如下: 一:在web.xml中配置:编码格式拦截器 & ...

  10. 一种解决eclipse中安装maven出错的方法

    1.安装步骤:https://jingyan.baidu.com/article/a17d5285feb4dd8099c8f26e.html 2.安装第三步的解决办法:m2e   路径换成  http ...