codeforces 374A
来源:互联网 发布:ubuntu install pip 编辑:程序博客网 时间:2024/06/06 05:38
题意:矩形网格中的一点加减a,b,求到四个顶点距离的最小值
思路: 归一法;
将一个点到四个顶点的距离,归成到其中一个顶点的距离,到其他三顶点的距离归成此点相对于矩形的对称点到特定点距离。因此不需要用bfs或者dfs去搜,同时跟据数据量去搜也会超时。(归成到(0,0)最好处理)
#include<iostream>#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>using namespace std;const int M=0xfffff;int f(int n,int m,int i,int j,int a,int b){if(i%a) return M;if(j%b) return M;if(abs(i/a-j/b)%2) return M;if(i==0&&j==0) return 0;if(n<=a||m<=b) return M;return max(i/a,j/b);}int main(){int n,m,i,j,a,b; cin>>n>>m>>i>>j>>a>>b; int ans=M; i--; j--; ans=min(ans,f(n,m,i,j,a,b)); ans=min(ans,f(n,m,n-i-1,j,a,b)); ans=min(ans,f(n,m,i,m-j-1,a,b)); ans=min(ans,f(n,m,n-i-1,m-j-1,a,b)); if(ans!=M) cout<<ans<<endl; else cout<<"Poor Inna and pony!"<<endl; }
0 0
- codeforces 374A
- CodeForces-a
- Codeforces 903A A
- CodeForces 374 A. Inna and Pink Pony
- CodeForces 374A. Divisible by Seven
- CodeForces 374A Inna and Pink Pony
- CodeForces 374A Inna and Pink Pony
- Codeforces Round #374 (Div. 2) A&B
- Codeforces Round #374 (Div. 2) A~D
- CodeForces 18A A - Triangle
- CodeForces 133A A. HQ9+
- codeforces 651A A. Joysticks
- 【Codeforces 597A】A. Divisibility
- 【 Codeforces 615A】A. Bulbs
- A. Divisibility CodeForces 597A
- codeforces 417A A. Elimination
- CodeForces 534A A. Exam
- codeforces#98 a
- iOS 中UI部分一些类的继承关系
- Chapter 3 | Stacks and Queues--实现数据结构模拟一个栈由几个子栈组成,并可以在指定子栈上进行出栈操作
- adaboost算法分类器的训练
- 在Ubuntu上为Android系统编写Linux内核驱动程序--实践中碰到的问题
- linux下使用axel下载百度网盘的资源
- codeforces 374A
- rational rose的下载和安装教程
- hdu4507(数位DP)
- 图文详解GPRS无线打印(什么是GPRS打印机?啥用途?如何使用?)
- HTML5 Canvas元素的教程
- 1035:放大的X
- 分页查询
- 1016 重要Phone Bills (25)
- Oracl 11g win7 install