In Korea, the naughtiness of the cheonggaeguri, a small frog, is legendary. This is a well-deserved reputation, because the frogs jump through your rice paddy at night, flattening rice plants. In the morning, after noting which plants have been flattened, you want to identify the path of the frog which did the most damage. A frog always jumps through the paddy in a straight line, with every hop the same length: 
 
Your rice paddy has plants arranged on the intersection points of a grid as shown in Figure-1, and the troublesome frogs hop completely through your paddy, starting outside the paddy on one side and ending outside the paddy on the other side as shown in Figure-2: 
 
Many frogs can jump through the paddy, hopping from rice plant to rice plant. Every hop lands on a plant and flattens it, as in Figure-3. Note that some plants may be landed on by more than one frog during the night. Of course, you can not see the lines showing the paths of the frogs or any of their hops outside of your paddy ?for the situation in Figure-3, what you can see is shown in Figure-4: 
 
From Figure-4, you can reconstruct all the possible paths which the frogs may have followed across your paddy. You are only interested in frogs which have landed on at least 3 of your rice plants in their voyage through the paddy. Such a path is said to be a frog path. In this case, that means that the three paths shown in Figure-3 are frog paths (there are also other possible frog paths). The vertical path down column 1 might have been a frog path with hop length 4 except there are only 2 plants flattened so we are not interested; and the diagonal path including the plants on row 2 col. 3, row 3 col. 4, and row 6 col. 7 has three flat plants but there is no regular hop length which could have spaced the hops in this way while still landing on at least 3 plants, and hence it is not a frog path. Note also that along the line a frog path follows there may be additional flattened plants which do not need to be landed on by that path (see the plant at (2, 6) on the horizontal path across row 2 in Figure-4), and in fact some flattened plants may not be explained by any frog path at all.

Your task is to write a program to determine the maximum number of landings in any single frog path (where the maximum is taken over all possible frog paths). In Figure-4 the answer is 7, obtained from the frog path across row 6.

Input

Your program is to read from standard input. The first line contains two integers R and C, respectively the number of rows and columns in your rice paddy, 1 <= R,C <= 5000. The second line contains the single integer N, the number of flattened rice plants, 3 <= N <= 5000. Each of the remaining N lines contains two integers, the row number (1 <= row number <= R) and the column number (1 <= column number <= C) of a flattened rice plant, separated by one blank. Each flattened plant is only listed once.

Output

Your program is to write to standard output. The output contains one line with a single integer, the number of plants flattened along a frog path which did the most damage if there exists at least one frog path, otherwise, 0.

Sample Input

6 7
14
2 1
6 6
4 2
2 5
2 6
2 7
3 4
6 1
6 2
2 3
6 3
6 4
6 5
6 7

Sample Output

7
题解:
  真是一道卡常数的题目,自己怎么剪都剪不过,(还有poj的机子太慢了吧!)
  首先n平方枚举两个点(因为两点确定一条直线),然后暴力On check,这个显然会t,考虑两个剪枝。
  1.显然我们枚举的起点,必须是第一个跳进来的点,这样才有意义。
  2.考虑把每个点都向棋盘的一个角落排序,这样的话,check就只要向一个方向check,因为反方向一定是check过的。
代码:(有一个点wa,如果能告诉我wa在哪里,感激不敬)
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <iostream>
#define MAXN 5010
#define RG register
using namespace std;
struct node{
int x,y;
}a[MAXN];
bool b[MAXN][MAXN];
int x[MAXN],y[MAXN];
int n,m,num,ans=; bool cmp(node hh,node hhh){
return hh.x<hhh.x;
return hh.y<hhh.y;
} int main()
{
scanf("%d%d%d",&n,&m,&num);
for(int i=;i<=num;i++) scanf("%d%d",&x[i],&y[i]),b[x[i]][y[i]]=,a[i].x=x[i],a[i].y=y[i];
sort(a+,a+num+,cmp);
for(RG int i=;i<=num;i++) x[i]=a[i].x,y[i]=a[i].y;
for(int i=;i<=num;i++)
for(int j=i+;j<=num;j++){
int num=;
RG int addx=x[j]-x[i],addy=y[j]-y[i],nowx=x[i],nowy=y[i];
if(nowx-addx<||nowy-addy<||nowx-addx>n||nowy-addy>m){
while(nowx>&&nowy>&&nowx<=n&&nowy<=m){
if(b[nowx][nowy]) num++;
else {num=;break;}
nowx+=addx,nowy+=addy;
}
if(num<) continue;
ans=max(ans,num);
}
}
if(ans==) puts("");
else printf("%d",ans);
return ;
}

The Troublesome Frog的更多相关文章

  1. POJ 1054 The Troublesome Frog

    The Troublesome Frog Time Limit: 5000MS Memory Limit: 100000K Total Submissions: 9581 Accepted: 2883 ...

  2. POJ1054 The Troublesome Frog

    题目来源:http://poj.org/problem?id=1054 题目大意: 有一种青蛙在晚上经过一片稻田,在庄稼上跳跃,会把庄稼压弯.这让农民很苦恼.我们希望通过分析青蛙跳跃的路径,找出对稻田 ...

  3. (中等) POJ 1054 The Troublesome Frog,记忆化搜索。

    Description In Korea, the naughtiness of the cheonggaeguri, a small frog, is legendary. This is a we ...

  4. IOI2002 POJ1054 The Troublesome Frog 讨厌的青蛙 (离散化+剪枝)

    Description In Korea, the naughtiness of the cheonggaeguri, a small frog, is legendary. This is a we ...

  5. POJ 1054 The Troublesome Frog(枚举+剪枝)

    题目链接 题意 :给你r*c的一块稻田,每个点都种有水稻,青蛙们晚上会从水稻地里穿过并踩倒,确保青蛙的每次跳跃的长度相同,且路线是直线,给出n个青蛙的脚印点问存在大于等于3的最大青蛙走的连续的脚印个数 ...

  6. poj 1054 The Troublesome Frog (暴力搜索 + 剪枝优化)

    题目链接 看到分类里是dp,结果想了半天,也没想出来,搜了一下题解,全是暴力! 不过剪枝很重要,下面我的代码 266ms. 题意: 在一个矩阵方格里面,青蛙在里面跳,但是青蛙每一步都是等长的跳, 从一 ...

  7. Poj 1054 The Troublesome Frog / OpenJudge 2812 恼人的青蛙

    1.链接地址: http://poj.org/problem?id=1054 http://bailian.openjudge.cn/practice/2812 2.题目: 总时间限制: 10000m ...

  8. 【POJ】1054 The Troublesome Frog

    题目是非常经典的搜索+剪枝.题意简言之就是,青蛙需要沿着直线踩着踏点通过田地,并且踏点需要至少为3.问哪条路径青蛙踩坏的作物最多.很好的一个条件是青蛙每次移动都是等间距的.题目需要注意将其排序. #i ...

  9. poj1054The Troublesome Frog

    链接 想O(n*n)的DP  怎么想都超内存 看讨论有说hash+DP过的 实现比较繁琐 大部分直接暴力过了 直接枚举每个i j 与他们在一条线上的点 是不是给出的点 注意它必须能跳进和跳出 #inc ...

随机推荐

  1. 洛谷 P1101单词方阵

    我已经,是这个世界上,最幸福的女孩了                                                                         ——<末日时 ...

  2. Kafka运维命令大全

    1.集群管理 前台启动broker bin/kafka-server-start.sh <path>/server.properties Ctrl + C 关闭 后台启动broker bi ...

  3. Linux服务器端口access改为trunk all

    1.确认可用网卡及vlan id eth5可用 vlan25:10.118.25.0/24 2.编辑网卡配置文件 vim /etc/sysconfig/network-scripts/ifcfg-et ...

  4. .Net基础篇_学习笔记_第三天_Convert类型转换

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  5. Spring+Mybatis整合的练手小项目(一)项目部署

    声明:教程是网上找的,代码是自己敲的 项目目录大致如下: 1. 首先创建Maven工程,在pom.xml中加入项目所需依赖: <?xml version="1.0" enco ...

  6. linux 操作系统级别监控 df 命令

    df命令可以查看当前系统磁盘空间的使用情况 命令:df -h du -sh * 查看目录文件暂用磁盘大小 如果磁盘空间不够,需清理磁盘 磁盘速度测试,如果磁盘性能不好,性能测试数据会不准确(读写速度) ...

  7. NPOI导出数值格式设置(我是保留四位小数,不足补0)

    看了网上好多帖子,都是保留两位小数的,写法是: HSSFDataFormat.GetBuiltinFormat("0.00"); 于是想四位小数,就是多加两个00,变成: HSSF ...

  8. JavaScript之深入对象(一)

    在之前的<JavaScript对象基础>中,我们大概了解了对象的创建和使用,知道对象可以使用构造函数和字面量方式创建.那么今天,我们就一起来深入了解一下JavaScript中的构造函数以及 ...

  9. PyCharm设置自己的默认模板

    1.File-Settings 2.Editor- Code Style - File and Code Templates - Python Script 需要设置什么内容,现在就可以写入了,相关变 ...

  10. jenkins自动化部署项目5 -- 系统管理-系统设置ssh配置

    [系统管理]-[系统设置] 如果应用服务(前端后台)要部署在linux服务器上,我选择的是用ssh 为了jenkins登录远程登录linux服务器可以免密登录,先配置公钥和私钥: 我是在windows ...