BZOJ1393 [Ceoi2008]knights
题意。。。上ceoi官网看吧。。。
首先打一下sg函数发现必胜态和必败态的分布位置是有规律的
于是我们只要知道最长步数的必胜态和最长步数的必败态哪个更长就可以了
然后再打一下步数的表。。。发现必败态的最长步数非常好确定,那么必胜态的步数搜一下就可以了!
1 /************************************************************** 2 Problem: 1393 3 User: rausen 4 Language: C++ 5 Result: Accepted 6 Time:992 ms 7 Memory:2372 kb 8 ****************************************************************/ 9 10 #include <cstdio> 11 #include <algorithm> 12 13 using namespace std; 14 const int dx[] = {-2, -2, -1, 1}; 15 const int dy[] = {1, -1, -2, -2}; 16 const int N = 2e5 + 5; 17 const int inf = 1e8; 18 19 int n, k; 20 int Ans, ansx[N], ansy[N]; 21 22 inline int read(); 23 inline void print (const int &); 24 25 inline bool calc_sg(int x, int y) { 26 if ((x % 4 == 1 || x % 4 == 2) && (y % 4 == 1 || y % 4 == 2)) return 0; 27 if (n % 4 == 1 && ((x == n && y != n - 1) || (y == n && x != n - 1))) return 0; 28 if (n % 4 == 0 && x == n && y == n) return 0; 29 return 1; 30 } 31 32 inline bool in(const int &x, const int &y) { 33 return (x > 0 && y > 0 && x <= n && y <= n); 34 } 35 36 #define X x + dx[k] 37 #define Y y + dy[k] 38 inline int find_lose(int x, int y) { 39 if (x == n || y == n) return 2 * ((int) (x + y - 2) / 4); 40 return 2 * ((int) (x + y - 1) / 4); 41 } 42 43 inline int find_win(int x, int y) { 44 int k, res = 0; 45 for (k = 0; k < 4; ++k) 46 if (in(X, Y) && calc_sg(X, Y) == 0) 47 res = max(res, find_lose(X, Y)); 48 return res + 1; 49 } 50 51 inline int calc_lose(int x, int y, int i) { 52 int k, tmp = inf; 53 for (k = 0; k < 4; ++k) 54 if (in(X, Y) && calc_sg(X, Y) == 1 && find_win(X, Y) < tmp) { 55 tmp = find_win(X, Y); 56 ansx[i] = X, ansy[i] = Y; 57 } 58 } 59 60 inline int calc_win(int x, int y, int i) { 61 int k, tmp = -1; 62 for (k = 0; k < 4; ++k) 63 if (in(X, Y) && calc_sg(X, Y) == 0 && tmp < find_lose(X, Y)) { 64 tmp = find_lose(X, Y); 65 ansx[i] = X, ansy[i] = Y; 66 } 67 } 68 #undef X 69 #undef Y 70 71 int main() { 72 int i, x, y, tmp, max_lose = 0, max_win = 0; 73 k = read(), n = read(); 74 for (i = 1; i <= k; ++i) { 75 x = read(), y = read(); 76 tmp = calc_sg(x, y); 77 if (tmp == 0) { 78 max_lose = max(max_lose, find_lose(x, y)); 79 calc_lose(x, y, i); 80 continue; 81 } 82 max_win = max(max_win, find_win(x, y)); 83 calc_win(x, y, i); 84 } 85 if (max_lose > max_win) puts("NO"); else { 86 puts("YES"); 87 for (i = 1; i <= k; ++i) { 88 print(ansx[i]), putchar(' '); 89 print(ansy[i]), putchar('\n'); 90 } 91 } 92 return 0; 93 } 94 95 inline int read() { 96 int x = 0; 97 char ch = getchar(); 98 while (ch < '0' || '9' < ch) 99 ch = getchar(); 100 while ('0' <= ch && ch <= '9') { 101 x = x * 10 + ch - '0'; 102 ch = getchar(); 103 } 104 return x; 105 } 106 107 inline void print(const int &x) { 108 static int tot, pr[20], t; 109 t = x, tot = 0; 110 while (t) 111 pr[++tot] = t % 10, t /= 10; 112 if (!tot) putchar('0'); 113 while(tot) 114 putchar('0' + pr[tot--]); 115 }
View Code
转载于:https://www.cnblogs.com/rausen/p/4352029.html
BZOJ1393 [Ceoi2008]knights相关推荐
- Codeforces Gym100812 L. Knights without Fear and Reproach-扩展欧几里得(exgcd)
补一篇以前的扩展欧几里得的题,发现以前写错了竟然也过了,可能数据水??? 这个题还是很有意思的,和队友吵了两天,一边吵一边发现问题??? L. Knights without Fear and Rep ...
- UVA1364 Knights of the Round Table(双连通分量、二分图染色,超详细解释)
整理的算法模板合集: ACM模板 UVA1364 Knights of the Round Table 题目中要求互相有憎恨关系的人不能坐在相邻的位置,一个圆桌可以很形象地看作是一个环,也就是说我们两 ...
- 被英特尔“冷落”的Knights Mill 悄然发布了
近日,英特尔"Knights Mill"的低调发布了.至于为什么会低调,原因很简单,英特尔Xeon Phi x205芯片是一个生态性质更强的产品. 英特尔至强Phi x205 Kn ...
- Bzoj 1391: [Ceoi2008]order 网络流,最大权闭合图
1391: [Ceoi2008]order Time Limit: 10 Sec Memory Limit: 64 MB Submit: 1105 Solved: 331 [Submit][Sta ...
- Game of Hyper Knights LightOJ - 1315
Game of Hyper Knights LightOJ - 1315 六个方向搜索 不能打表,打表很麻烦,记录不了旧状态 #include <bits/stdc++.h> #defin ...
- 【POJ - 2942】Knights of the Round Table(点双连通分量,二分图判断奇环奇圈)
题干: Being a knight is a very attractive career: searching for the Holy Grail, saving damsels in dist ...
- LightOJ1171 Knights in Chessboard (II)(二分图最大点独立集)
题目 Source http://www.lightoj.com/volume_showproblem.php?problem=1171 Description Given an m x n ches ...
- POJ-2488 A Knights Journey-深度优先搜索DFS
POJ-2488 A Knights Journey-深度优先搜索 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 37974 A ...
- bzoj 1671: [Usaco2005 Dec]Knights of Ni 骑士(BFS)
1671: [Usaco2005 Dec]Knights of Ni 骑士 Time Limit: 5 Sec Memory Limit: 64 MB Submit: 416 Solved: 26 ...
最新文章
- 看图说话:OpenGL模型矩阵和投影矩阵
- C语言库自带的二分查找函数bsearch函数的使用示例
- keras concatenate_Keras结合Keras后端搭建个性化神经网络模型
- 《从零开始系列-Project 2010视频教程 (102课时)》 教你进行有效的项目管理
- java 搭建企业应用框架_java培训一般要学多久
- 【技术解决方案】Windows平台下摄像头采集方案
- 怎样设置电脑壁纸_怎样设置电脑的资料定时备份到移动硬盘里
- (126)FPGA面试题-做了哪些FPGA时序约束?
- scrolling=no 无法根据坐标获取元素_提高三坐标测量精度,要记住这几招
- 前端常用插件、工具类库汇总,不要重复造轮子啦!!!
- hibernate 里面 mysql dialect 配置
- 北风网 传智播客 视频地址
- 关于DNF的多媒体包NPK文件的那些事儿(8) - DNF里的DDS图像
- Android Studio4.0解决Gradle下载超时问题
- 插头dp ——从入门到跳楼
- 《山月记》一定有那么一刻,我们曾迷茫怀疑
- 迅捷路由器造成计算机无法上网,迅捷FAST无线路由器设置好了却上不了网现象的原因及解决方法介绍...
- Sound Forge使用技巧之制作手机铃声
- C语言 最大公约数与素数探求
- 小学计算机设备管理 维护制度,信息化各种设备使用、管理及维护制度