poj 1054
来源:互联网 发布:网络刷手被骗怎么追回 编辑:程序博客网 时间:2024/04/28 15:23
解题思路:这道题其实比较简单,就是找斜率相同且间距相同的点。
首先,就是要找到两点,确定好斜率,然后就判断这两点是否在起始位置。
其次,确定好斜率就确定了两个点之间的距离,如果某两点之间的间距不满足的话,那么这个点肯定不是这个方向上的。
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>const int maxn = 5005;struct node{int row,col;int next;}p[maxn];int r,c,n;bool vis[maxn][maxn];bool cmp(node a,node b){if(a.col == b.col) return a.row < b.row;return a.col < b.col;}int main(){while(scanf("%d%d",&r,&c)!=EOF){scanf("%d",&n);memset(vis,false,sizeof(vis));for(int i = 1; i <= n; i++){scanf("%d%d",&p[i].row,&p[i].col);vis[p[i].row][p[i].col] = true;}std::sort(p+1,p+1+n,cmp);int ans = 0;for(int i = 1; i <= n; i++)for(int j = i + 1; j <= n; j++){int disx = p[j].row - p[i].row;int disy = p[j].col - p[i].col;if(p[i].row - disx > 0 && p[i].row - disx <= r && p[i].col - disy > 0 && p[i].col - disy <= c) continue;int tmpx = p[j].row + disx;int tmpy = p[j].col + disy;int cnt = 0;while(tmpx > 0 && tmpx <= r && tmpy > 0 && tmpy <= c){if(vis[tmpx][tmpy]) cnt++;else{cnt = 0; break;}tmpx += disx;tmpy += disy;}ans = std::max(ans,cnt);}if(ans) printf("%d\n",ans+2);else printf("%d\n",ans);}return 0;}
0 0
- poj 1054
- poj-1054
- poj 1054
- poj 1054 搜索
- POJ 1054 暴力搜索
- poj 1054 枚举+hash
- POJ 1054 枚举
- poj 1054 技巧枚举
- POJ
- poj
- POJ
- POJ
- poj
- poj
- POJ
- POJ
- poj
- POJ
- hdu3416Marriage Match IV
- Block实现原理
- RunTime
- 使用pgpool-ii 搭建postgresql 高可用、负载均衡架构
- linux实战(十)----shell监控tomcat服务是否正常----综合运用
- poj 1054
- Git alias
- 经典数据挖掘算法(介绍了包括18大数据挖掘在内的多种经典数据挖掘算法)
- 基本控件
- 使用XCode打包ipa
- 如何在Mac中安装好Ruby环境
- SpringMVC源码解读 - HandlerMapping - RequestMappingHandlerMapping初始化
- java 常用测试框架
- Android Tool——Monkey自动化测试