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 & ...
随机推荐
- json、javaBean、xml互转的几种工具介绍 (转载)
工作中经常要用到Json.JavaBean.Xml之间的相互转换,用到了很多种方式,这里做下总结,以供参考. 现在主流的转换工具有json-lib.jackson.fastjson等,我为大家一一做简 ...
- iOS - Swift 基本语法
前言 Swift 全面支持 Unicode 符号. Swift 中的定义和实现是在同一个单元中的,通常一个 Swift 源代码单文件是以 ".Swift" 结尾的. Swift 不 ...
- SAP接口编程 之 JCo3.0系列(05) : Exception Handling
JCO3.0的Exception,常用的Exception如下: JCoException 继承自java.lang.Exception,是JCo3中Exception的基类. JCoRuntimeE ...
- Java中值传递的实质,形式参数与实际参数。引用传递。
值传递 package ch5; /** * Created by Jiqing on 2016/11/9. */ public class Transfer { public static void ...
- Android 开源项目分类汇总(转)
Android 开源项目分类汇总(转) ## 第一部分 个性化控件(View)主要介绍那些不错个性化的 View,包括 ListView.ActionBar.Menu.ViewPager.Galler ...
- html页面的绝对路径和相对路径
在用springmvc架构开发网站的过程中,离不开开发前台html页面,html经常需要使用本地相关的资源,如:图片,js,css等,一般情况下,我们可以通过使用相对路径的方式来对这些资源进行指向和访 ...
- Android开发面试经——2.常见Android基础笔试题
标签: androidAndroid基础Android面试题Android笔试题 2015-03-12 15:04 3361人阅读 评论(3) 收藏 举报 分类: Android开发(29) 版 ...
- 免费在线客服QQ_网页接入及使用说明
首先,注册一个QQ (haha,我觉得也是废话) 到QQ推广的网站设置,生成代码 链接:http://shang.qq.com/v3/widget.html 选择“免费开通”,然后就会看到下图,一般只 ...
- 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 / ...
- 20160808_安装JDK7u79
1.将 jdk-7u79-linux-x64.tar.gz 解压,得到文件夹“jdk1.7.0_79” 将 文件夹“jdk1.7.0_79” 复制到 “/usr/java/”下 2.配置环境变量: 文 ...