要点

  • 会发现本质上棋盘分成了若干个独立集,本集合内的点放不放棋子并不影响其他集合内的
  • 集合的划分方式就是满棋盘跳马步直到全跳过了,然后每个集合就分成两队,我们选人多的那队放棋子,人少那队当禁区
const int maxn = 1e3 + 5;
const int nx[] = {-2, -2, -1, -1, 1, 1, 2, 2};
const int ny[] = {-1, 1, -2, 2, -2, 2, -1, 1}; int n, m;
bool grid[maxn][maxn];
int ans, cnt[2]; void dfs(int i, int j, int c) {
cnt[c]++;
grid[i][j] = 1;
rep(k, 0, 7) {
int x = i + nx[k], y = j + ny[k];
if (x < 1 || x > n || y < 1 || y > m || grid[x][y]) continue;
dfs(x, y, 1 - c);
}
} int main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> n >> m;
rep(i, 1, n)
rep(j, 1, m)
if (!grid[i][j]) {
cnt[0] = cnt[1] = 0;
dfs(i, j, 0);
ans += max(cnt[0], cnt[1]);
}
cout << ans << '\n';
return 0;
}

Codeforces 142B(二分染色、搜索)的更多相关文章

  1. uva 10004 Bicoloring(dfs二分染色,和hdu 4751代码差不多)

    Description In the ``Four Color Map Theorem" was proven with the assistance of a computer. This ...

  2. (简单) POJ 2492 A Bug's Life,二分染色。

    Description Background Professor Hopper is researching the sexual behavior of a rare species of bugs ...

  3. Codeforces 27D(二分染色)

    要点 将边作为染色,如果交叉则异色 #include <cstdio> #include <algorithm> #include <functional> usi ...

  4. Codeforces 1144F(二分染色)

    发现奇环不可行,偶环可行,考虑二分图.然后染色,方向全都从一种指向另一种就可以了,随意. ; int n, m, color[maxn]; vector<int> vc[maxn]; ve ...

  5. Codeforces Round #427 (Div. 2) Problem D Palindromic characteristics (Codeforces 835D) - 记忆化搜索

    Palindromic characteristics of string s with length |s| is a sequence of |s| integers, where k-th nu ...

  6. hiho_1139_二分+bfs搜索

    题目 给定N个点和M条边,从点1出发,到达点T.寻找路径上边的个数小于等于K的路径,求出所有满足条件的路径中最长边长度的最小值. 题目链接:二分     最小化最大值,考虑采用二分搜索.对所有的边长进 ...

  7. poj 3897 Maze Stretching 二分+A*搜索

    题意,给你一个l,和一个地图,让你从起点走到终点,使得路程刚好等于l. 你可以选择一个系数,把纵向的地图拉伸或收缩,比如你选择系数0.5,也就是说现在上下走一步消耗0.5的距离,如果选择系数3,也就是 ...

  8. CodeForces - 363D --二分和贪心

    题目:CodeForces - 363D 题意:给定n个学生,其中每个学生都有各自的私己钱,并且自己的私己钱只能用在自己买自行车,不能给别人. 给定m个自行车,每个自行车都有一个价格. 给定公有财产a ...

  9. Codeforces 799D Field expansion - 搜索 - 贪心

    In one of the games Arkady is fond of the game process happens on a rectangular field. In the game p ...

随机推荐

  1. grep 强大的文本搜索工具

    1.grep -r "History folder does't exist:" * :中间是要搜索的文本,* 表示全部显示出来

  2. input光标使用caret-color改变颜色

    本文转载自:https://www.zhangxinxu.com/wordpress/2018/01/css-caret-color-first-line/ CSS caret-color属性可以改变 ...

  3. Algo: Dynamic programming

    Copyright © 1900-2016, NORYES, All Rights Reserved. http://www.cnblogs.com/noryes/ 欢迎转载,请保留此版权声明. -- ...

  4. UVA - 11327

    UVA - 11327https://vjudge.net/problem/28358/origin求欧拉函数的前缀和,二分查找到那个位置,再从它开始暴力gcd找 #include <iostr ...

  5. 关于Slice的一些补充说明

    s[m:n:l] 规则总结如下. (1) 范围 [m,n),从m开始轮询:超出范围后选边界值. l>0 l<0 关于边界值 (2) 把字符串完全反序,用 s[::-1]. 有些文档上说 s ...

  6. thinkphp 区间查询

    ThinkPHP支持对某个字段的区间查询,例如: 富瑞华大理石平台厂家哪家好 $map['id'] = array(array('gt',1),array('lt',10)) ; 得到的查询条件是:  ...

  7. Python-进程(1)

    目录 操作系统发展史 穿孔卡片 联机批处理系统 统计批处理系统 单道 多道技术 空间上复用 时间上复用 并行与并发 进程 程序与进程 进程调度 进程的三个状态 就绪态 运行态 阻塞态 同步和异步 阻塞 ...

  8. Java-Shiro:Shiro

    ylbtech-Java-Shiro:Shiro 1.返回顶部 1. Apache Shiro是一个强大且易用的Java安全框架,执行身份验证.授权.密码和会话管理.使用Shiro的易于理解的API, ...

  9. 服务器迁移部署PosWeb

    绑定 基本配置 高级配置

  10. Jeecg-Boot 2.0.1 版本发布,前后端分离快速开发平台

    Jeecg-Boot项目简介 Jeecg-boot 是一款基于代码生成器的快速开发平台! 采用前后端分离技术:SpringBoot,Mybatis,Shiro,JWT,Vue & Ant De ...