poj1054The Troublesome Frog
想O(n*n)的DP 怎么想都超内存 看讨论有说hash+DP过的 实现比较繁琐
大部分直接暴力过了
直接枚举每个i j 与他们在一条线上的点 是不是给出的点
注意它必须能跳进和跳出
#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
using namespace std;
#define N 5010
bool flag[N][N];
struct node
{
int x,y;
}p[N];
bool cmp(node a,node b)
{
if(a.x==b.x)
return a.y<b.y;
return a.x<b.x;
}
int main()
{
int i,j,k,n,r,c;
while(scanf("%d%d",&r,&c)!=EOF)
{
memset(flag,,sizeof(flag));
scanf("%d",&n);
for(i = ; i <= n ;i++)
{
scanf("%d%d",&p[i].x,&p[i].y);
flag[p[i].x][p[i].y] = ;
}
sort(p+,p+n+,cmp);
int ans=,ff=;
for(i = ; i <= n ; i++)
for(j = i+; j <= n ; j++)
{
int tx = p[j].x-p[i].x;
int ty = p[j].y - p[i].y;
int ox = p[j].x;
int oy = p[j].y;
if(p[i].x-tx>=&&p[i].x-tx<=r&&p[i].y-ty>=&&p[i].y-ty<=c)
continue;
ff = ;
for(k = ; ; k++)
{
ox+=tx;
oy+=ty;
if(ox>r||oy>c||ox<||oy<)
break;
if(!flag[ox][oy])
{
ff = ;
break;
}
}
if(ff)
ans = max(ans,k);
}
if(ans>)
printf("%d\n",ans);
else
printf("0\n");
}
return ;
}
poj1054The Troublesome Frog的更多相关文章
- POJ 1054 The Troublesome Frog
The Troublesome Frog Time Limit: 5000MS Memory Limit: 100000K Total Submissions: 9581 Accepted: 2883 ...
- POJ1054 The Troublesome Frog
题目来源:http://poj.org/problem?id=1054 题目大意: 有一种青蛙在晚上经过一片稻田,在庄稼上跳跃,会把庄稼压弯.这让农民很苦恼.我们希望通过分析青蛙跳跃的路径,找出对稻田 ...
- (中等) POJ 1054 The Troublesome Frog,记忆化搜索。
Description In Korea, the naughtiness of the cheonggaeguri, a small frog, is legendary. This is a we ...
- IOI2002 POJ1054 The Troublesome Frog 讨厌的青蛙 (离散化+剪枝)
Description In Korea, the naughtiness of the cheonggaeguri, a small frog, is legendary. This is a we ...
- The Troublesome Frog
In Korea, the naughtiness of the cheonggaeguri, a small frog, is legendary. This is a well-deserved ...
- POJ 1054 The Troublesome Frog(枚举+剪枝)
题目链接 题意 :给你r*c的一块稻田,每个点都种有水稻,青蛙们晚上会从水稻地里穿过并踩倒,确保青蛙的每次跳跃的长度相同,且路线是直线,给出n个青蛙的脚印点问存在大于等于3的最大青蛙走的连续的脚印个数 ...
- poj 1054 The Troublesome Frog (暴力搜索 + 剪枝优化)
题目链接 看到分类里是dp,结果想了半天,也没想出来,搜了一下题解,全是暴力! 不过剪枝很重要,下面我的代码 266ms. 题意: 在一个矩阵方格里面,青蛙在里面跳,但是青蛙每一步都是等长的跳, 从一 ...
- 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
题目是非常经典的搜索+剪枝.题意简言之就是,青蛙需要沿着直线踩着踏点通过田地,并且踏点需要至少为3.问哪条路径青蛙踩坏的作物最多.很好的一个条件是青蛙每次移动都是等间距的.题目需要注意将其排序. #i ...
随机推荐
- 区分.net、c#、asp.net三者间的关系
1..net(dot net) .net是一个平台,抽象的平台概念. 实现形式是库:①定义了基本的类型(通用类型系统CTS,common type system). ②包含.net公共语言运行库( ...
- HDU 1058 Humble Number
Humble Number Problem Description A number whose only prime factors are 2,3,5 or 7 is called a humbl ...
- 暑假集训(2)第三弹 ----- 食物链(poj1182)
C - 食物链 Crawling in process... Crawling failed Time Limit:1000MS Memory Limit:10000KB 64bit ...
- InstallShield 版本转换
InstallShield : 如何用低版本 打开高版本的工程 InstallShield 每个版本都有对应的版本号SchemaVersion,如下所示 InstallShield Versi ...
- Qt-获取网络接口信息的综合示例
在前面的文章中介绍了与 获 取 本 机 网 络 信 息 相 关 的 类 常 用 的 有 4 个 , 分 别 是 : QHostAddress, QHostInfo, QNetworkInterface ...
- Linux C 程序 两变量值交换(FIVE)
example:1.运算符: #include<stdio.h> int main(){ int a , b , c ,d ; a = ; b = a++;//先赋值给b,a再自增 c = ...
- 关于$.fn
今天看一篇文章,里面的一段代码出现了$.fn,第一次见到这样的写法,于是跑去问度娘...代码如下: $.fn.scrollUnique = function() { return $(this).ea ...
- HTML5元素拖拽实现示例
HTML5现在前端圈中,已然成为一个不那么新的技术词汇了,很多公司也把HTML5也当成了硬性的技能要求,但是很多前端恐怕都不了解HTML5的拖拽怎么实现吧. 看了下极客学院的视频,大概的了解了下思路. ...
- JavaScript的语法要点 1 - Lexically Scoped Language
作为从一开始接触C.C++.C#的程序员而言,JavaScript的语法对我来说有些古怪,通过最近一年的接触,对它有了一定的了解,于是想把它的一些语法要点记录下来. 1. Block Scope vs ...
- javascript cookie 操作
<html> <head> <meta charset="utf-8"> <title>Javascript cookie</ ...