题目链接

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

思路 : 暴力了一下,顺便剪剪枝就可以过。。。。

 //POJ1054
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm> using namespace std ; struct node{
int row,col ;
}plant[];
int ab[][] ;
int r,c,n ; bool cmp(const node a,const node b)
{
if(a.row == b.row)
return a.col < b.col ;
return a.row < b.row ;
}
bool judge(int x,int y)
{
if(x > && x <= r && y > && y <= c) return true ;
return false ;
} int xxxx(int x,int y,int dx,int dy)
{
int cnt = ;
while(judge(x,y))
{
if(!ab[x][y]) return ;//会出现交叉路径所得
cnt ++ ;
x += dx ;
y += dy ;
}
return cnt ;
} int main()
{
scanf("%d %d %d",&r,&c,&n) ;
memset(ab,,sizeof(ab)) ;
for(int i = ; i < n ; i++)
{
scanf("%d %d",&plant[i].row,&plant[i].col) ;
ab[plant[i].row][plant[i].col] = ;
}
sort(plant,plant+n,cmp) ;
int cnt = ;
for(int i = ; i < n ; i++)
{
for(int j = i+ ; j < n ; j++)
{
int dx = plant[j].row-plant[i].row ;
int dy = plant[j].col-plant[i].col ;
if(plant[i].row + cnt *dx > r || cnt*dy + plant[i].col>c) continue ;//青蛙的起点肯定在稻田外;
if(judge(plant[i].row-dx,plant[i].col-dy)) continue ;//该点的直线上的脚印一定要大于上一次的点数;
if(!judge(plant[i].row + cnt*dx,plant[i].col+cnt * dy)) continue ;//多于上一点的基础上点要在稻田内;
cnt = max(cnt,xxxx(plant[i].row,plant[i].col,dx,dy)) ;
}
}
if(cnt < )
printf("0\n") ;
else printf("%d\n",cnt) ;
return ;
}

POJ 1054 The Troublesome Frog(枚举+剪枝)的更多相关文章

  1. POJ 1054 The Troublesome Frog 枚举

    这个题分类是dp,想了一会没有想出来,就去看别人题解了.发现别人题解全是暴力枚举= =.复杂度超过 N^2,但可能是剪枝的作用,没有超时. 思路:将所有点按坐标由小到大排序.两两枚举点p1,p2,并判 ...

  2. POJ 1054 The Troublesome Frog

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

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

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

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

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

  5. POJ - 1054 The Troublesome Frog 模拟 枚举优化。

    题意:有个R*C的格网.上面有若干个点,这些点可以连成一些直线,满足:这些点在直线上均匀排布(也就是间隔相等),直线的两段穿过网格(也就是第一个,最后一个在网格的边界附近) 求某条直线上最多的点数 题 ...

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

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

  7. 【POJ】1054 The Troublesome Frog

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

  8. POJ 2531 Network Saboteur (枚举+剪枝)

    题意:给你一个图,图中点之间会有边权,现在问题是把图分成两部分,使得两部分之间边权之和最大. 目前我所知道的有四种做法: 方法一:状态压缩 #include <iostream> #inc ...

  9. POJ1054 The Troublesome Frog

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

随机推荐

  1. 10+ powerful debugging tricks with Visual Studio

    10+ powerful debugging tricks with Visual Studio Original link : http://www.codeproject.com/Articles ...

  2. 经典SQL语句大全 学者必看

    一.基础 .说明:创建数据库 CREATE DATABASE database-name .说明:删除数据库 drop database dbname .说明:备份sql server --- 创建 ...

  3. c#获取今天星期几

    System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.GetDayName(DateTime.Now.DayOfWeek)

  4. Hello,cnblog。

    This my blog 

  5. MemProof教程

    简介 MemProof(内存清道夫)是AutomatedQA出品的一款非常不错的检测内存泄漏和资源泄漏的免费调试工具,适合于WIN32平台下使用DELPHI/C++ BUILDER开发的应用程序. 利 ...

  6. oracle 11g 通过透明网关链接mysql

    之前转载过一篇在Windows上安装的,自己实际在centos上安装了一下.以下为安装记录: 一.操作系统环境 二.数据库环境(用oracle用户登录) 三.DG4ODBC 在Oracle DB 11 ...

  7. opencv的初体验

    http://guoming.me/opencv-config  这篇文章有讲解opencv的安装与配置 一些常用库 opencv_core249d.lib opencv_imgproc249d.li ...

  8. 【转】Web标准中的常见问题

    本文转自http://www.tracefact.net/Misc/Common-Problems-Of-Web-Standard.aspx 引言 大概在2004年的时候,Web标准的概念藉由一本名为 ...

  9. CHARINDEX,PATINDEX,STUFF函数

    -- CHARINDEX函数 -- 返回字符或者字符串在另一个字符串中的起始位置. -- 语法:CHARINDEX(expression1 , expression2 [,start_location ...

  10. WPF-控件-层级控件-Menu-嵌套结构

    <?xml version="1.0" encoding="utf-8" ?> <Data xmlns=""> &l ...