BZOJ1393 [Ceoi2008]knights
题意。。。上ceoi官网看吧。。。
首先打一下sg函数发现必胜态和必败态的分布位置是有规律的
于是我们只要知道最长步数的必胜态和最长步数的必败态哪个更长就可以了
然后再打一下步数的表。。。发现必败态的最长步数非常好确定,那么必胜态的步数搜一下就可以了!
/**************************************************************
Problem: 1393
User: rausen
Language: C++
Result: Accepted
Time:992 ms
Memory:2372 kb
****************************************************************/ #include <cstdio>
#include <algorithm> using namespace std;
const int dx[] = {-, -, -, };
const int dy[] = {, -, -, -};
const int N = 2e5 + ;
const int inf = 1e8; int n, k;
int Ans, ansx[N], ansy[N]; inline int read();
inline void print (const int &); inline bool calc_sg(int x, int y) {
if ((x % == || x % == ) && (y % == || y % == )) return ;
if (n % == && ((x == n && y != n - ) || (y == n && x != n - ))) return ;
if (n % == && x == n && y == n) return ;
return ;
} inline bool in(const int &x, const int &y) {
return (x > && y > && x <= n && y <= n);
} #define X x + dx[k]
#define Y y + dy[k]
inline int find_lose(int x, int y) {
if (x == n || y == n) return * ((int) (x + y - ) / );
return * ((int) (x + y - ) / );
} inline int find_win(int x, int y) {
int k, res = ;
for (k = ; k < ; ++k)
if (in(X, Y) && calc_sg(X, Y) == )
res = max(res, find_lose(X, Y));
return res + ;
} inline int calc_lose(int x, int y, int i) {
int k, tmp = inf;
for (k = ; k < ; ++k)
if (in(X, Y) && calc_sg(X, Y) == && find_win(X, Y) < tmp) {
tmp = find_win(X, Y);
ansx[i] = X, ansy[i] = Y;
}
} inline int calc_win(int x, int y, int i) {
int k, tmp = -;
for (k = ; k < ; ++k)
if (in(X, Y) && calc_sg(X, Y) == && tmp < find_lose(X, Y)) {
tmp = find_lose(X, Y);
ansx[i] = X, ansy[i] = Y;
}
}
#undef X
#undef Y int main() {
int i, x, y, tmp, max_lose = , max_win = ;
k = read(), n = read();
for (i = ; i <= k; ++i) {
x = read(), y = read();
tmp = calc_sg(x, y);
if (tmp == ) {
max_lose = max(max_lose, find_lose(x, y));
calc_lose(x, y, i);
continue;
}
max_win = max(max_win, find_win(x, y));
calc_win(x, y, i);
}
if (max_lose > max_win) puts("NO"); else {
puts("YES");
for (i = ; i <= k; ++i) {
print(ansx[i]), putchar(' ');
print(ansy[i]), putchar('\n');
}
}
return ;
} inline int read() {
int x = ;
char ch = getchar();
while (ch < '' || '' < ch)
ch = getchar();
while ('' <= ch && ch <= '') {
x = x * + ch - '';
ch = getchar();
}
return x;
} inline void print(const int &x) {
static int tot, pr[], t;
t = x, tot = ;
while (t)
pr[++tot] = t % , t /= ;
if (!tot) putchar('');
while(tot)
putchar('' + pr[tot--]);
}
BZOJ1393 [Ceoi2008]knights的更多相关文章
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
- BZOJ 1391: [Ceoi2008]order [最小割]
1391: [Ceoi2008]order Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 1509 Solved: 460[Submit][Statu ...
- POJ2942 Knights of the Round Table[点双连通分量|二分图染色|补图]
Knights of the Round Table Time Limit: 7000MS Memory Limit: 65536K Total Submissions: 12439 Acce ...
- POJ 2942 Knights of the Round Table
Knights of the Round Table Time Limit: 7000MS Memory Limit: 65536K Total Submissions: 10911 Acce ...
- LightOJ1171 Knights in Chessboard (II)(二分图最大点独立集)
题目 Source http://www.lightoj.com/volume_showproblem.php?problem=1171 Description Given an m x n ches ...
- 【BZOJ1671】[Usaco2005 Dec]Knights of Ni 骑士 BFS
[Usaco2005 Dec]Knights of Ni 骑士 Description 贝茜遇到了一件很麻烦的事:她无意中闯入了森林里的一座城堡,如果她想回家,就必须穿过这片由骑士们守护着的森林.为 ...
- Knights of the Round Table-POJ2942(双连通分量+交叉染色)
Knights of the Round Table Description Being a knight is a very attractive career: searching for the ...
- poj 2942 Knights of the Round Table 圆桌骑士(双连通分量模板题)
Knights of the Round Table Time Limit: 7000MS Memory Limit: 65536K Total Submissions: 9169 Accep ...
- LightOJ 1315 - Game of Hyper Knights(博弈sg函数)
G - Game of Hyper Knights Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%lld & ...
随机推荐
- 10款Windows命令行工具
Windows下CMD不好用,远没有Linux,或者一些SSH工具用起来方便.其实Windows下,也有一些不错的工具替代CMD: 0.powercmd经过比较,我最终选择了这款,这里补充一下截图:
- 使用一个封装的json删除方法
<!-- 前台js代码:其实现的目的:利用异步的封装方法实现增删改操作!--> <script type="text/javascript"> functi ...
- Python学习(10)元组
目录 Python 元组 访问元组 修改元组 删除元组 元组运算符 元组索引,截取 无关闭分隔符 元组内置函数 Python 元组 Python的元组与列表类似,不同之处在于元组的元素不能修改. 元组 ...
- Matlab中的persistent变量
persistent, 用于定义persistent变量.persistent变量对于声明它的函数来说是局部的,但是当退出该函数时,该变量仍然保存在内存中,数值并不变.persistent变量与全局变 ...
- (十)makefile
一.Makefile的作用和意义(1)工程项目中c文件太多管理不方便,因此用Makefile来做项目管理,方便编译链接过程.(2)uboot和linux kernel本质上都是C语言的项目,都由很多个 ...
- 3 javascript
3 javascript javascript基础 html: 负责了一个页面的结构. css: 负责了一个页面的样式. javascript: 负责与用户进行交互. 1997年欧洲的计算机 ...
- python中用filter求素数
#用filter求素数 #生成器,生成一个无限序列 def _odd_iter(): n=1 while True: n=n+2 yield n #筛选函数 def _not_divisible(n) ...
- 联想手机#P1来了#P1背后的故事系列
http://bbs.lenovo.com/forum.php?mod=viewthread&fid=928&tid=560992&extra=page%3D1 联想手机#P1 ...
- VB6 GDI+ 入门教程[5] 基础绘图小结
http://vistaswx.com/blog/article/category/tutorial/page/2 VB6 GDI+ 入门教程[5] 基础绘图小结 2009 年 6 月 18 日 4条 ...
- javascript正则表达式介绍
正则表达式就是一个用来描述字符模式的对象.它被用来在文本中执行模式匹配(pattern-matching)以及”查找-替换”(search-and-replace)的任务.javascript中正则的 ...