日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

BZOJ1393 [Ceoi2008]knights

發布時間:2025/4/16 编程问答 19 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。