Codeforces Round #454 D. Seating of Students
分三类
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的更多相关文章
- 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 解 水题,按照题意模拟一下就行了 如果是 ‘ ! ...
- Codeforces Round #454
Masha and Bears Tic-Tac-Toe Shockers Seating of Students Party Power Tower Reverses
- Educational Codeforces Round 11 B. Seating On Bus 水题
B. Seating On Bus 题目连接: http://www.codeforces.com/contest/660/problem/B Description Consider 2n rows ...
- Codeforces Round #454 C. Shockers【模拟/hash】
C. Shockers time limit per test 2 seconds memory limit per test 256 megabytes input standard input o ...
- 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个询问,每个询问给出一个 ...
- Codeforces Round #454 Div. 1
B:考虑2*m怎么构造.因为要求相邻的数不能再相邻,容易想到黑白染色之类的东西,考虑染个色然后大概把黑点扔一边白点扔一边.显然m<=3时无解.对m>4,m为偶数时,如1 2 3 4 5 6 ...
- Codeforces Round #454 Div. 2 A B C (暂时)
A. Masha and bears 题意 人的体积为\(V\),车的大小为\(size\),人能钻进车的条件是\(V\leq size\),人对车满意的条件是\(2V\geq size\). 现知道 ...
- 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 ...
- Codeforces Round #486 (Div. 3) A. Diverse Team
Codeforces Round #486 (Div. 3) A. Diverse Team 题目连接: http://codeforces.com/contest/988/problem/A Des ...
随机推荐
- BZOJ 2733: [HNOI2012]永无乡 [splay启发式合并]
2733: [HNOI2012]永无乡 题意:加边,询问一个连通块中k小值 终于写了一下splay启发式合并 本题直接splay上一个节点对应图上一个点就可以了 并查集维护连通性 合并的时候,把siz ...
- HDU 3595 GG and MM [Every-SG]
传送门 题意: 两个数$x,y$,一个人的决策为让大数减去小数的任意倍数(结果不能为负),出现0的人胜 一堆这样的游戏同时玩 Every-SG 游戏规定,对于还没有结束的单一游戏,游戏者必须对该游戏进 ...
- C# 简单内存补丁
写在开头:看了一些视频教程,感觉OD为什么别人学个破解那么容易,我就那么难了呢,可能是没有那么多时间吧. 解释:个人见解:所谓内存补丁,即:通过修改运行程序的内容,来达到某种目的的操作.修改使用Ope ...
- solr-搭建与使用过程中问题总结-链接
以下错误可以确定在CDH版本Hbase集群+Lily hbase indexer+solrCloud的环境中可以解决,有开源版本解决成功案例的请在下方评论. 1.If you see this err ...
- php扩展开发实战教程(1)
我的开发环境: Ubuntu16.04 apt方式安装的php5.6, apache,mysql等 由于我的本机用的是apt方式安装的php,所以我这里从头开始用最精简的方式,编译安装一个php5.4 ...
- 用最简单的例子实现jQuery图片即时上传
[http://www.cnblogs.com/Zjmainstay/archive/2012/08/09/jQuery_upload_image.html] 最近看了一些jQuery即时上传的插件, ...
- 编译安装python3.6后pip3无法安装模块问题处理
编译安装python3.6之后,使用pip3命令安装第三方库效果如图所示: pip is configured with locations that require TLS/SSL, however ...
- PHP实现WebService的简单示例和实现步骤
首先我创建的文件有: api.php api的接口类文件 api.wsdl 我创建产生的最后要调用的接口文件 cometrue.php 注册service api类内容的所有内容的执行文件 creat ...
- Python自动化--语言基础2--运算符、格式化输出、条件语句、循环语句、列表、元组
运算符包括:算术运算符.比较运算符.赋值运算符.逻辑运算符.成员运算符.身份运算符 算术运算符 % 取模(余数) // 取相除的整数部分 / (5/2=2.5) 比较运算符 == 等于 ! ...
- MySQL数据库基础(一)(启动/停止、登录/退出、语法规范及最基础操作)
1.启动/停止MySQL服务 启动:net start mysql 停止:net stop mysql 2.MySQL登录/退出 登录:mysql 参数:如果连接的是本地服务器,一般用命令:my ...