分三类
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. SDN第四次作业

    作业链接 1.阅读 了解SDN控制器的发展 http://www.sdnlab.com/13306.html http://www.docin.com/p-1536626509.html 了解ryu控 ...

  2. python 3.x 爬虫基础---Urllib详解

    python 3.x 爬虫基础 python 3.x 爬虫基础---http headers详解 python 3.x 爬虫基础---Urllib详解 前言 爬虫也了解了一段时间了希望在半个月的时间内 ...

  3. centos7下安装apache服务器httpd的yum方式安装

    转自Clement-Xu的csdn博客 http://blog.csdn.net/clementad/article/details/41620631   Apache在Linux系统中,其实叫&qu ...

  4. 架构师入门:搭建双注册中心的高可用Eureka架构(基于项目实战)

    本文的案例是基于 架构师入门:搭建基本的Eureka架构(从项目里抽取) 改写的. 在上文里,我们演示Eureka客户端调用服务的整个流程,在这部分里我们将在架构上有所改进.大家可以想象下,在上文里案 ...

  5. maven常用命令介绍

    mvn 3.0.4 创建maven项目命令  mvn  archetype:generate   -DgroupId=damocles-autocredit -DartifactId=damocles ...

  6. 想想我们能拿HoloLens 做点什么

    作为一个微软员工,顿时感觉好了很多. 中午吃饭同事们热烈讨论这东东: 1. 看电视 2. 办公 3. 用HoloLens 玩3d 游戏.满公园跑. 4. 看书 5. 开车的时候,实时显示地图 6. 一 ...

  7. MysqL自动提交机制的关闭

    MysqL在执行一句数据库操作命令的时候,通常都是自动提交的.常用引擎下有两种,分别是MyIsam和InnoDB,MyIsam是不支持事务处理的,但InnoDB支持,但InnoDB在不开启事务处理的情 ...

  8. Redis限制在规定时间范围内登陆错误次数限制

    在博客里之前有过一篇文章是 <PHP结合Redis来限制用户或者IP某个时间段内访问的次数>,这篇文章的思路也是一样的.看下代码吧 //登录错误次数校验 $key = "logi ...

  9. Mysql数据库建立索引的优缺点有哪些?

    索引是对数据库表中一列或多列的值进行排序的一种结构,使用索引可快速访问数据库表中的特定信息. 什么是索引 数据库索引好比是一本书前面的目录,能加快数据库的查询速度. 例如这样一个查询:select * ...

  10. qt 使用msvc编译器出现乱码如何解决?字符串中存在空格?

    开发环境: 1.win7 64位 2.qt版本 windows-x86-msvc2015-5.9.0 如何解决? 1.设置qt文件编码 设置 默认UTF-8 如果编码是 UTF-8 则添加. 2.使用 ...