sgu 147. Black-white king 思路 坑 难度:1
147. Black-white king
memory limit per test: 4096 KB
output: standard output
In the case of positive answer (i.e. if the probability of black-white king to win is nonzero) find the minimal number of moves necessary to probable victory. Otherwise find the minimal total number of moves of black and white kings necessary to meet. Remember the order of moves: white king, black king, and black-white king. Any king can move to any of the 8 adjacent cells.
1 1
5 3
2 3
1
这道题看起来很像水题,解起来很像水题,但是有两点 1 黑白王的最短路是指步数最短不是指单纯的路程最短 2 一开始就在一个格子上则yes,0
其中第一点很坑,即使经过队友开导我现在也抱着这是坑题和题意不明的心态
注意黑白王的运动状态可能是以初始点为中心,2*步数+1为正方形边长的空心正方形
这里有几组测试数据,直接找个ac程序对拍吧,比如我写在下面的
10
1 10
1 1
5 5
5
1 1
5 3
2 3
10
1 1
5 5
3 3
5
10 10
5 5
3 4
3
1 1
2 2
3 3
200
1 1
20 100
25 17
500
1 1
200 200
100 100
10
1 1
4 3
2 5
100
10 40
40 30
25 25
21
1 10
21 10
1 5
25
1 10
21 10
21 1
4
3 1
1 2
1 2
66
4 57
31 35
17 38
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
int n,p1,q1,p2,q2,p3,q3;
bool ins(int x,int y1,int y2,int x3,int x4,int y3,int y4){
// printf("x %d y1 %d y2 %d x3 %d y3 %d x4 %d y4 %d\n",x,y1,y2,x3,y3,x4,y4);
if(x<=x4&&x>=x3&&((y1<=y3&&y2>=y3)||(y1<=y4&&y2>=y4)))return true;
if(x==x3||x==x4){
if(max(y1,y3)<=min(y2,y4))return true;
}
return false;
}
int pos(int x){
if(x<1)return 1;
if(x>n)return n;
return x;
}
int calc(){
int sumstep=abs(p1-p2);
int maxstep=abs(p1-p2)/2-1;
if(maxstep<=0)return -1;
int x1=p2==p1?0:(p2-p1)/abs(p2-p1);
int xx,ymax,ymin;
for(int i=1;i<=maxstep;i++){
// printf("%d:\n%d %d %d %d\n",i,pos(q1-i),pos(q1+i),pos(q2-sumstep+i),pos(q2+sumstep-i));
xx=p1+x1*i;
ymin=max(pos(q1-i),pos(q2-sumstep+i));
ymax=min(pos(q1+i),pos(q2+sumstep-i));
if(ins(xx,ymin,ymax,p3-i,p3+i,q3-i,q3+i))return i;
xx=p2-x1*i;
ymin=max(pos(q2-i),pos(q1-sumstep+i));
ymax=min(pos(q2+i),pos(q1+sumstep-i));
if(ins(xx,ymin,ymax,p3-i,p3+i,q3-i,q3+i))return i; }
return -1;
}
int main(){
//freopen("data.txt","w",stdout);
scanf("%d%d%d%d%d%d%d",&n,&p1,&q1,&p2,&q2,&p3,&q3);
if((p1==p3&&q1==q3)||(p2==p3&&q2==q3)){puts("YES\n0");return 0;}
if(abs(p1-p2)<abs(q1-q2)){
swap(p1,q1);swap(p2,q2);swap(p3,q3);
}
int ans=calc();
if(ans==-1)printf("NO\n%d\n",abs(p1-p2)-1);
else {
printf("YES\n%d\n",ans);
}
return 0;
}
sgu 147. Black-white king 思路 坑 难度:1的更多相关文章
- SGU 156 Strange Graph 欧拉回路,思路,汉密尔顿回路 难度:3
http://acm.sgu.ru/problem.php?contest=0&problem=156 这道题有两种点 1. 度数>2 在团中的点,一定连接一个度数为2的点 2. 度数等 ...
- SGU 147.Black-white king
时间限制:0.25s 空间限制:4M 题意: 在一个N*N(N <= 106)的棋盘上,有三个棋子:黑王.白王.黑白王,它们的行走方式一致,每秒向8个方向中的任意一个行走一步. 现在黑王和白王想 ...
- sgu 129 Inheritance 凸包,线段交点,计算几何 难度:2
129. Inheritance time limit per test: 0.25 sec. memory limit per test: 4096 KB The old King decided ...
- HDU 4791 Alice's Print Service 思路,dp 难度:2
A - Alice's Print Service Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & ...
- sgu 146. The Runner 取模技巧 难度:1
146. The Runner time limit per test: 0.25 sec.memory limit per test: 4096 KB input: standard inputou ...
- SGU 144. Meeting 概率dp 几何概率分布 难度:0
144. Meeting time limit per test: 0.25 sec. memory limit per test: 4096 KB Two of the three members ...
- ZOJ 3646 Matrix Transformer 二分匹配,思路,经典 难度:2
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4836 因为要使对角线所有元素都是U,所以需要保证每行都有一个不同的列上有U,设 ...
- GCJ 2015-Qualification-B Infinite House of Pancakes 枚举,思路,误区 难度:3
https://code.google.com/codejam/contest/6224486/dashboard#s=p1 题目不难,教训记终生 题目给了我们两种操作:1 所有人都吃一个,简记为消除 ...
- SGU 246. Black & White(数论)
题意: 有2*n-1个黑色和白色的珠子组成的环形项链,求至少需要多少颗黑色珠子才能使任意排列的项链中都存在两个黑珠间有n个珠子. (2*n-1<=2^31-1); Solution: 先分析n= ...
随机推荐
- SVN跨版本库迁移目录并保留提交日志
现在有一份代码code在版本库reposA/dirB/下,现在想把它移动到reposB/dirAA/下,本来打算交给SA做,没想到SA似乎 也不太懂的样子.于是,自己在VPS搭建了一个svnserve ...
- Python开发【Django】:Model操作(二)
Model操作 1.操作汇总: # 增 # # models.Tb1.objects.create(c1='xx', c2='oo') 增加一条数据,可以接受字典类型数据 **kwargs # obj ...
- nginx中获取真实ip(转)
原文:http://blog.csdn.net/a936676463/article/details/8961504 server { listen 80; server_name lo ...
- Mirror--程序访问镜像数据库的超时机制
程序在访问有镜像的数据库和无镜像的数据库时,采用的链接超时时间算法不一样,因此会导致在在有镜像的数据库上设置了15 S的超时时间,而实际的超时时间仅为3.6 S,从而导致有镜像的数据库更容易超时. 在 ...
- mysql备份的4种方式
mysql备份的4种方式 转载自:https://www.cnblogs.com/SQL888/p/5751631.html 总结: 备份方法 备份速度 恢复速度 便捷性 功能 一般用于 cp 快 快 ...
- php中使用Curl、socket、file_get_contents三种方法POST提交数据
抓取远程内容,之前一直都在用file_get_content函数,其实早就知道有curl这么一个好东西的存在,但是看了一眼后感觉使用颇有些复杂,没有file_get_content那么简单,再就是需求 ...
- linux/Mac使用du查看目录占用的磁盘大小
[1]du命令用来查看目录或文件所占用磁盘空间的大小.常用选项组合为: du -sh [2]若要查看一个目录下每个文件和文件夹的磁盘占用空间,使用如下命令: du -ah --max-depth=1 ...
- maven运行junit用例并生成报告
原文地址https://blog.csdn.net/hdyrz/article/details/78398964 测试类如下: [java] view plain copypackage com.mm ...
- Bootstrap按钮组学习
简介 通过按钮组容器把一组按钮放在同一行里.通过与按钮插件联合使用,可以设置为单选框或多选框的样式和行为. 按钮组中的工具提示和弹出框需要特别的设置 当为 .btn-group 中的元素应用工具提示或 ...
- mysql锁机制之综述(一)
https://zhuanlan.zhihu.com/p/29150809 一.数据库有锁机制的原因. 数据库锁定机制简单来说,就是数据库为了保证数据的一致性和有效性,而使各种共享资源在被并发访问变得 ...