题意。。。上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[] = {-, -, -, };
  15. const int dy[] = {, -, -, -};
  16. const int N = 2e5 + ;
  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 % == || x % == ) && (y % == || y % == )) return ;
  27. if (n % == && ((x == n && y != n - ) || (y == n && x != n - ))) return ;
  28. if (n % == && x == n && y == n) return ;
  29. return ;
  30. }
  31.  
  32. inline bool in(const int &x, const int &y) {
  33. return (x > && y > && 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 * ((int) (x + y - ) / );
  40. return * ((int) (x + y - ) / );
  41. }
  42.  
  43. inline int find_win(int x, int y) {
  44. int k, res = ;
  45. for (k = ; k < ; ++k)
  46. if (in(X, Y) && calc_sg(X, Y) == )
  47. res = max(res, find_lose(X, Y));
  48. return res + ;
  49. }
  50.  
  51. inline int calc_lose(int x, int y, int i) {
  52. int k, tmp = inf;
  53. for (k = ; k < ; ++k)
  54. if (in(X, Y) && calc_sg(X, Y) == && 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 = -;
  62. for (k = ; k < ; ++k)
  63. if (in(X, Y) && calc_sg(X, Y) == && 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 = , max_win = ;
  73. k = read(), n = read();
  74. for (i = ; i <= k; ++i) {
  75. x = read(), y = read();
  76. tmp = calc_sg(x, y);
  77. if (tmp == ) {
  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 = ; i <= k; ++i) {
  88. print(ansx[i]), putchar(' ');
  89. print(ansy[i]), putchar('\n');
  90. }
  91. }
  92. return ;
  93. }
  94.  
  95. inline int read() {
  96. int x = ;
  97. char ch = getchar();
  98. while (ch < '' || '' < ch)
  99. ch = getchar();
  100. while ('' <= ch && ch <= '') {
  101. x = x * + ch - '';
  102. ch = getchar();
  103. }
  104. return x;
  105. }
  106.  
  107. inline void print(const int &x) {
  108. static int tot, pr[], t;
  109. t = x, tot = ;
  110. while (t)
  111. pr[++tot] = t % , t /= ;
  112. if (!tot) putchar('');
  113. while(tot)
  114. putchar('' + pr[tot--]);
  115. }

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. json、javaBean、xml互转的几种工具介绍 (转载)

    工作中经常要用到Json.JavaBean.Xml之间的相互转换,用到了很多种方式,这里做下总结,以供参考. 现在主流的转换工具有json-lib.jackson.fastjson等,我为大家一一做简 ...

  2. iOS - Swift 基本语法

    前言 Swift 全面支持 Unicode 符号. Swift 中的定义和实现是在同一个单元中的,通常一个 Swift 源代码单文件是以 ".Swift" 结尾的. Swift 不 ...

  3. SAP接口编程 之 JCo3.0系列(05) : Exception Handling

    JCO3.0的Exception,常用的Exception如下: JCoException 继承自java.lang.Exception,是JCo3中Exception的基类. JCoRuntimeE ...

  4. Java中值传递的实质,形式参数与实际参数。引用传递。

    值传递 package ch5; /** * Created by Jiqing on 2016/11/9. */ public class Transfer { public static void ...

  5. Android 开源项目分类汇总(转)

    Android 开源项目分类汇总(转) ## 第一部分 个性化控件(View)主要介绍那些不错个性化的 View,包括 ListView.ActionBar.Menu.ViewPager.Galler ...

  6. html页面的绝对路径和相对路径

    在用springmvc架构开发网站的过程中,离不开开发前台html页面,html经常需要使用本地相关的资源,如:图片,js,css等,一般情况下,我们可以通过使用相对路径的方式来对这些资源进行指向和访 ...

  7. Android开发面试经——2.常见Android基础笔试题

     标签: androidAndroid基础Android面试题Android笔试题 2015-03-12 15:04 3361人阅读 评论(3) 收藏 举报  分类: Android开发(29)  版 ...

  8. 免费在线客服QQ_网页接入及使用说明

    首先,注册一个QQ (haha,我觉得也是废话) 到QQ推广的网站设置,生成代码 链接:http://shang.qq.com/v3/widget.html 选择“免费开通”,然后就会看到下图,一般只 ...

  9. Oracle Names - Oracle_SID /db_name instance_name service_names / service_name / sid / sid_name

    很多人还是困惑,下面再次尝试从几个不同角度区分一下: Oracle_SID / db_name, instance_name, service_names  / service_name, sid / ...

  10. 20160808_安装JDK7u79

    1.将 jdk-7u79-linux-x64.tar.gz 解压,得到文件夹“jdk1.7.0_79” 将 文件夹“jdk1.7.0_79” 复制到 “/usr/java/”下 2.配置环境变量: 文 ...