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 & ...
随机推荐
- sar 找出系统瓶颈的利器
sar 找出系统瓶颈的利器sar是System Activity Reporter(系统活动情况报告)的缩写.sar工具将对系统当前的状态进行取样,然后通过计算数据和比例来表达系统的当前运行状态.它的 ...
- JQery 中的 $(".bb:eq(1)") eq () 解释。。
这是一段代码: <div id="bb">a</div> <div id="bb">b</div> <di ...
- 项目问题总结:Block内存泄露 以及NSTimer使用问题
BLock的内存泄露 在我们代码中关于block的使用可以说随处可见,第一次接触block的时候是关于UIView的块动画,那时觉得block的使用好神奇,再后来分析总结为block其实就是一个c语言 ...
- JavaScript中Trim(),TrimStart(),TrimEnd()的实现
//去除字符串头尾空格或指定字符 String.prototype.Trim= function(c) { if(c==null||c=="") { var str= this.r ...
- Linux命令:traceroute(windows中为tracert)
通过traceroute 我们可以知道信息从你的计算机到互联网另一端的主机是走的什么路径.当然每次数据包由某一同样的出发点(source)到达某一同样的目的地(destination)走的路径可能会不 ...
- CTEX里的函数、符号及特殊字符
CTEX里的函数.符号及特殊字符 声调 语法 效果 语法 效果 语法 效果 \bar{a} \acute{a} \check{a} \grave{a} \tilde{a} \hat ...
- Microsoft SQL Server
instance / database / schema / object login / user / schema (dbo) sequence Collation PSM: Both Insta ...
- u盘安装ubuntu server 14.04 以及No CD-ROM drive was detected 错误
u盘安装ubuntu server 14.04 1:下载ubuntu server14的 iso镜像文件 2:下载 UltraISO U盘镜像制作工具 : 3:使用Ultra iOS 将下载好的 is ...
- 在腾讯云上创建您的SQL Cluster(3)
版权声明:本文由李斯达原创文章,转载请注明出处: 文章原文链接:https://www.qcloud.com/community/article/250 来源:腾云阁 https://www.qclo ...
- js到处excel
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...