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 & ...
随机推荐
- 使用ansible批量管理远程服务器
使用ansible批量管理远程服务器 背景 本地需要管理远程的一批服务器,主要执行以下任务: 1) 将本地的文件复制到远端所有服务器: 2) 需要在远程服务器中执行一个个命令: 远端服务器路径并非完全 ...
- Object-C : Block的实现方式
摘自:http://www.cnblogs.com/GarveyCalvin/p/4204167.html> Date : 2015-12-4 前言:我们可以把Block当作一个闭包函数,它可以 ...
- hdu 5587 规律
题意:开始序列{1}; 一次变换{1,1,2}: 两次变换{1,1,2,1,2,2,3} ... 求s[n];题解:打表 S1,S2,S4,S8,S16,S32......公式 S[n]=S[最近的比 ...
- VirtualBox全屏切换
用VirtualBox的时候,如果设置为全屏,想再切换回来,没有什么菜单,只有通过键盘的快捷键来操作,才可以恢复. 我常常忘掉,所以老是得去找,以后需要记住这几个按键的快捷键. 1.全屏与非全屏切换: ...
- iOS - OC NSCache 缓存
前言 NSCache 是苹果提供的一个专门用来做缓存的类,当内存 "不足" 或超过限制的时候,会自动清理缓存,使用时可以指定缓存的数量和成本.用法与 NSMutableDictio ...
- hibernate对象关系实现(一)一对多
hibernate是对jdk一个封装工具,实现对象和数据库之间数据映射.使用时涉及到四个问题:a.对象之间的关系在类中的体现:b,对象关系对应的数据库中表之间体现:c.实现a,b在hibernate的 ...
- ubuntu_杂
1. 虚拟机安装的 ubuntu 12.04,在关闭了 一段时间不操作就屏保 和 锁屏 之后, 在一段时间之后 虚拟机的屏幕还是变黑了,貌似是 os将 显示器关闭了. 这个相关的设置是在哪里? 相关设 ...
- HDU3247 AC自动机+dp
题意:给出n个资源,m个病毒,将资源串拼接成一个串,必须包含所有的资源串,可以重叠,但是不能包含病毒,问最小的长度为多少 题解:所有串建AC自动机.对以资源串结尾的结点跑bfs,求出到其他资源串结尾的 ...
- web设计经验<九>教你测试手机网页的5大方法
我们知道手机浏览器的使用量每天都在增长,根据StatCounter的统计数据,手机和平板的使用量约占30%的网络流量,这意味着消费者耗费在移动版网页上的时间比以往任何时候都高.可即使具备诸如移动端优先 ...
- Android监听Button和ImageButton控件的点击事件
一.onClick事件 Button和ImageButton都有一个onClick事件,通过自身的.setOnClickListener(OnClickListener)方法添加点击事件 所有的控件都 ...