cf A. Inna and Pink Pony(思维题)
2024-10-19 01:28:33
题目: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 ;
}
最新文章
- 命令行工具aspnet_regiis.exe实现加密和解密web.config
- 悲剧啊!Mysql的上古BUG!!!
- 网页3D引擎“Babylon.JS”入门教程翻译总结
- Drools给日志打标签
- Hashing function
- AOP 之 6.1 AOP基础(拾陆)
- 【Latex】如何在Latex中插入伪代码 —— clrscode3e
- $http POST 转字符串
- IPointCollection,ISegmentCollection和IGeometryCollection
- linux下ifconfig, DNS以及route配置
- 《转》如何成为一个牛逼的C/C++程序员?
- 基于 Zookeeper 的分布式锁实现
- 基于PySpark的网络服务异常检测系统 阶段总结(二)
- jqgrid 让隐藏的列在编辑状态时出现且可编辑
- Oracle Tuxedo工作站客户端与服务端的样例程序
- MySQLdb &; pymsql
- Selenium之IE浏览器的启动问题及解决
- json、jsonp的定义和区别
- 从原型链看DOM--Document类型
- CentOS 7安装简介及基本操作
热门文章
- ubuntu更新源,简单两步搞定
- Kakfa揭秘 Day3 Kafka源码概述
- max_size, capacity and size 的区别
- Google code: Why ‘Everything up-to-date’ when pushing (git)
- sql之事务和并发
- C#和Js 编码和解码方法
- gif格式的图片不能存在与包含js目录的路径中?
- qwt 6.1.0集成进Qt creator 2.8.1步骤
- js注册登录审核
- js添加创建节点和合并节点