POJ 1054 The Troublesome Frog(枚举+剪枝)
题意 :给你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(枚举+剪枝)的更多相关文章
- POJ 1054 The Troublesome Frog 枚举
这个题分类是dp,想了一会没有想出来,就去看别人题解了.发现别人题解全是暴力枚举= =.复杂度超过 N^2,但可能是剪枝的作用,没有超时. 思路:将所有点按坐标由小到大排序.两两枚举点p1,p2,并判 ...
- POJ 1054 The Troublesome Frog
The Troublesome Frog Time Limit: 5000MS Memory Limit: 100000K Total Submissions: 9581 Accepted: 2883 ...
- Poj 1054 The Troublesome Frog / OpenJudge 2812 恼人的青蛙
1.链接地址: http://poj.org/problem?id=1054 http://bailian.openjudge.cn/practice/2812 2.题目: 总时间限制: 10000m ...
- poj 1054 The Troublesome Frog (暴力搜索 + 剪枝优化)
题目链接 看到分类里是dp,结果想了半天,也没想出来,搜了一下题解,全是暴力! 不过剪枝很重要,下面我的代码 266ms. 题意: 在一个矩阵方格里面,青蛙在里面跳,但是青蛙每一步都是等长的跳, 从一 ...
- POJ - 1054 The Troublesome Frog 模拟 枚举优化。
题意:有个R*C的格网.上面有若干个点,这些点可以连成一些直线,满足:这些点在直线上均匀排布(也就是间隔相等),直线的两段穿过网格(也就是第一个,最后一个在网格的边界附近) 求某条直线上最多的点数 题 ...
- (中等) POJ 1054 The Troublesome Frog,记忆化搜索。
Description In Korea, the naughtiness of the cheonggaeguri, a small frog, is legendary. This is a we ...
- 【POJ】1054 The Troublesome Frog
题目是非常经典的搜索+剪枝.题意简言之就是,青蛙需要沿着直线踩着踏点通过田地,并且踏点需要至少为3.问哪条路径青蛙踩坏的作物最多.很好的一个条件是青蛙每次移动都是等间距的.题目需要注意将其排序. #i ...
- POJ 2531 Network Saboteur (枚举+剪枝)
题意:给你一个图,图中点之间会有边权,现在问题是把图分成两部分,使得两部分之间边权之和最大. 目前我所知道的有四种做法: 方法一:状态压缩 #include <iostream> #inc ...
- POJ1054 The Troublesome Frog
题目来源:http://poj.org/problem?id=1054 题目大意: 有一种青蛙在晚上经过一片稻田,在庄稼上跳跃,会把庄稼压弯.这让农民很苦恼.我们希望通过分析青蛙跳跃的路径,找出对稻田 ...
随机推荐
- 3.servlet实现页面的跳转
效果: 在网页的输入框中输入lily,跳到成功的页面(请求转发),输入的不是lily则跳到百度的页面(跳到工程之外的页面,则是请求重定向) 1.建Web project“2Servlet_Basic” ...
- linux 编译内核[scripts/kconfig/dochecklxdialog] 错误
administrator@ubuntu:~/linux-2.6.28-omap$ make menuconfig *** Unable to find the ncurses libraries o ...
- PHP安全之register_globals
一.register_globals = Off 和 register_globals = On的区别 register_globals是php.ini里的一个配置,这个配置影响到php如何接收传递过 ...
- 水面波浪形View--第三方开源--WaveView(电量、能量、容量指示)
这种WaveView在一些常见的APP开发中,以水面波浪波形的形象的生动展示手机还剩余多少电量,存储容量还有多少,比较形象直观生动. WaveView在github上的项目主页是:https://gi ...
- Optimize str2date function
The job can be any string date format convert to AX date format. so that, Do not need to specify str ...
- MvvmLight for Xamarin.Forms
一.Xamarin.Forms 不使用框架时的绑定 需要注意的是BindingContent,不是DataContent <ContentPage xmlns="http://xama ...
- ApacheBench 使用教程
ab压力测试 ab是Apache超文本传输协议(HTTP)的性能测试工具.其设计意图是描绘当前所安装的Apache的执行性能. 主要是显示你安装的Apache每秒可以处理多少个请求. 格式: ./ab ...
- CentOS 7.0安装MPlayer
自带的播放器不管rmvb还是mp4都不能播放,也搜索不到解码器. CentOS7epel装不上所以也没有rpmfusion,所以决定自己编译mplayer 首先是要获取源代码. 首先是主程序的源代码. ...
- Java 图形编程 二:布局管理器之边界布局
package second; import java.awt.*; import java.awt.event.WindowAdapter; import java.awt.event.Window ...
- Reactor模式
对象行为类的设计模式,对同步事件分拣和派发.别名Dispatcher(分发器) Reactor模式是处理并发I/O比较常见的一种模式,用于同步I/O,中心思想是将所有要处理的I/O事件注册到一个中心I ...