题意。。。上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的更多相关文章

  1. bzoj AC倒序

    Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...

  2. BZOJ 1391: [Ceoi2008]order [最小割]

    1391: [Ceoi2008]order Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 1509  Solved: 460[Submit][Statu ...

  3. POJ2942 Knights of the Round Table[点双连通分量|二分图染色|补图]

    Knights of the Round Table Time Limit: 7000MS   Memory Limit: 65536K Total Submissions: 12439   Acce ...

  4. POJ 2942 Knights of the Round Table

    Knights of the Round Table Time Limit: 7000MS   Memory Limit: 65536K Total Submissions: 10911   Acce ...

  5. LightOJ1171 Knights in Chessboard (II)(二分图最大点独立集)

    题目 Source http://www.lightoj.com/volume_showproblem.php?problem=1171 Description Given an m x n ches ...

  6. 【BZOJ1671】[Usaco2005 Dec]Knights of Ni 骑士 BFS

    [Usaco2005 Dec]Knights of Ni 骑士 Description  贝茜遇到了一件很麻烦的事:她无意中闯入了森林里的一座城堡,如果她想回家,就必须穿过这片由骑士们守护着的森林.为 ...

  7. Knights of the Round Table-POJ2942(双连通分量+交叉染色)

    Knights of the Round Table Description Being a knight is a very attractive career: searching for the ...

  8. poj 2942 Knights of the Round Table 圆桌骑士(双连通分量模板题)

    Knights of the Round Table Time Limit: 7000MS   Memory Limit: 65536K Total Submissions: 9169   Accep ...

  9. LightOJ 1315 - Game of Hyper Knights(博弈sg函数)

    G - Game of Hyper Knights Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%lld & ...

随机推荐

  1. python_way ,day22 tonardo

    python_way day22 1.tonardo 2.cookie 3.api认证 一.tonardo: a.tonardo 初识 #!/usr/bin/env python3# Created ...

  2. iOS - TouchLock 手势解锁

    1.手势解锁的创建 代码封装见 QExtension QLockView.h #import <UIKit/UIKit.h> @interface QLockView : UIView / ...

  3. Spring 自动装配 Bean

    Spring3系列8- Spring 自动装配 Bean 1.      Auto-Wiring ‘no’ 2.      Auto-Wiring ‘byName’ 3.      Auto-Wiri ...

  4. NTT【51nod】1514 美妙的序列

    题意:1~n 的全排列中,有多少个排列满足任意从中间切成两段后,左边段的最大值大于右边段的最小值? 例如:n为3时有3种 2 3 1 3 1 2 3 2 1 解释:比如 2 3 1 (2) (3 1) ...

  5. 07 SQL优化技术

    本章提要------------------------------------------------------调优技术及什么时候使用------------------------------- ...

  6. Python学习(9)列表

    目录 Python 列表 访问列表中的值 更新列表 删除列表元素 列表脚本操作符 列表截取 列表函数&方法 Python 列表(List) 序列是Python中最基本的数据结构.序列中的每个元 ...

  7. JavaSE复习_8 泛型程序设计

    今晚看了core Java的泛型部分,万万没有想到,当时看培训班视频入门的一带而过的泛型,有这样多的细节,整理了一下书里面提到的一些自认为的重点,方便以后观阅.由于是复习,一些基础知识跳过. △泛型类 ...

  8. Xcode好用的插件

    注释:每当Xcode升级之后,都会导致原有的Xcode插件不能使用,这是因为每个插件的Info.plist中记录了该插件兼容Xcode版本的DVTPlugInCompatibilityUUID,而每个 ...

  9. java中如何把后台数据推送到页面上 【后续编辑】

    https://my.oschina.net/yongqingfan/blog/535749 http://www.blogjava.net/BearRui/archive/2010/05/19/fl ...

  10. 20160808_Linux服务

    1. http://bbs.csdn.net/topics/370100269 2. http://blog.csdn.net/csfreebird/article/details/8239933 h ...