分三类
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. USACO 状压DP练习[3]

    1725 题意:$m*n:\ m,n \le 12$的牧场,有的格子不能选,相邻不能同时选,求方案数 $f[i][j]$前$i$行当前行选的集合为$j$ #include <iostream&g ...

  2. POJ2318 TOYS[叉积 二分]

    TOYS Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 14433   Accepted: 6998 Description ...

  3. 使用TransactionScope(轻量级事务)实现数据库操作事务

    TransactionScope是.Net Framework 2.0滞后,新增了一个名称空间.它的用途是为数据库访问提供了一个"轻量级"[区别于:SqlTransaction]的 ...

  4. 10位时间戳转为C#格式时间

    /// <summary> /// 10位时间戳转为C#格式时间 /// </summary> /// <param name=”timeStamp”></p ...

  5. ASP.NET Core 发布 centos7 配置守护进程

    ASP.NET Core应用程序发布linux在shell中运行是正常的.可一但shell关闭网站也就关闭了,所以要配置守护进程, 用的是Supervisor,本文主要记录配置的过程和过程遇到的问题 ...

  6. 阶段小项目2:显示bin格式图片

    #include<stdlib.h>#include<stdio.h>#include<string.h>#include<error.h>#inclu ...

  7. ADO.NET 对数据操作

    public static class SQLHelper { static string connString = ConfigurationManager.ConnectionStrings[&q ...

  8. JS声明对象时属性名加引号与不加引号的问题

    般情况下属性名加引号和不加引号是都可以的,效果是一样的. var obj = { name : '你好', 'age' : 1, }; document.write( obj['name'] + '& ...

  9. jQuery中animate()方法用法实例

    本文实例讲述了jQuery中animate()方法用法.分享给大家供大家参考.具体分析如下: 此方法用于创建自定义动画,并且能够规定动画执行时长.擦除效果.动画完成后还可以地触发一个回调函数. ani ...

  10. HDU 3001(状态压缩dp)

    状态压缩dp的第一题! 题意:Mr ACMer想要进行一次旅行,他决定访问n座城市.Mr ACMer 可以从任意城市出发,必须访问所有的城市至少一次,并且任何一个城市访问的次数不能超过2次.n座城市间 ...