题目:http://codeforces.com/contest/374/problem/A

题意:求到达边界的最小步数。。

刚开始以为是 bfs,不过数据10^6太大了,肯定不是。。。

一个思维题,要注意超边界。。。

 #include <iostream>
#include <cstring>
#include <algorithm>
using namespace std; const int INF=(<<);
int n,m,x,y,a,b; int ok(int x1,int y1)
{
if(x1<) x1=-x1;
if(y1<) y1=-y1;
if(x1%a==&&y1%b==)//能恰好 到达边界
{
if((x1/a-y1/b)%==)//而且两个的差为偶数。。
{
if(x1/a>y1/b)
return x1/a;
else
return y1/b;
}
}
return INF;
}
int main()
{
int d[];
while(cin>>n>>m>>x>>y>>a>>b)
{
if((x==&&y==m)||(x==n&&y==)||(x==n&&y==m)||(x==&&y==))
{
cout<<""<<endl;
continue;
}
if(a>=n||b>=m)//有可能一步就会越界。。
{
cout<<"Poor Inna and pony!"<<endl;
continue;
}
d[]=ok(x-,y-m);
d[]=ok(x-n,y-);
d[]=ok(x-n,y-m);
d[]=ok(x-,y-);
sort(d,d+);
if(d[]==INF)
cout<<"Poor Inna and pony!"<<endl;
else
cout<<d[]<<endl;
}
return ;
}

最新文章

  1. 命令行工具aspnet_regiis.exe实现加密和解密web.config
  2. 悲剧啊!Mysql的上古BUG!!!
  3. 网页3D引擎“Babylon.JS”入门教程翻译总结
  4. Drools给日志打标签
  5. Hashing function
  6. AOP 之 6.1 AOP基础(拾陆)
  7. 【Latex】如何在Latex中插入伪代码 —— clrscode3e
  8. $http POST 转字符串
  9. IPointCollection,ISegmentCollection和IGeometryCollection
  10. linux下ifconfig, DNS以及route配置
  11. 《转》如何成为一个牛逼的C/C++程序员?
  12. 基于 Zookeeper 的分布式锁实现
  13. 基于PySpark的网络服务异常检测系统 阶段总结(二)
  14. jqgrid 让隐藏的列在编辑状态时出现且可编辑
  15. Oracle Tuxedo工作站客户端与服务端的样例程序
  16. MySQLdb &amp; pymsql
  17. Selenium之IE浏览器的启动问题及解决
  18. json、jsonp的定义和区别
  19. 从原型链看DOM--Document类型
  20. CentOS 7安装简介及基本操作

热门文章

  1. ubuntu更新源,简单两步搞定
  2. Kakfa揭秘 Day3 Kafka源码概述
  3. max_size, capacity and size 的区别
  4. Google code: Why ‘Everything up-to-date’ when pushing (git)
  5. sql之事务和并发
  6. C#和Js 编码和解码方法
  7. gif格式的图片不能存在与包含js目录的路径中?
  8. qwt 6.1.0集成进Qt creator 2.8.1步骤
  9. js注册登录审核
  10. js添加创建节点和合并节点