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 ...
随机推荐
- asp.net 异步处理
#region 异步测试 //委托 public delegate void PrintDelegate(string s); [WebMethod] public string yibu() { / ...
- Java线程间通信--生产者消费者
class ProducerConsumerDemo { public static void main(String[] args) { Resource r = new ...
- c# DataTable 中 Select 和 Clone 用法结合
C# DataTable是存放数据的一个离线数据库,将数据一下加载到内存. DataTable.Select ()方法: Select();//全部查出来 Select(过滤条件);//根据过滤 ...
- NOIP201501&&02
NOIP201501金币 试题描述 国王将金币作为工资,发放给忠诚的骑士.第一天,骑士收到一枚金币:之后两天(第二天和第三天) ,每天收到两枚金币:之后三天(第四.五.六天) ,每天收到三枚金币:之后 ...
- C++(指针)
指针在编程中有时很重要的作用 我们可以用它完成一些看似不可能完成的任务 #include<iostream>using namespace std;void square(int *n){ ...
- QtSQL学习笔记(3)- 执行SQL语句
QSqlQuery类提供了一个用于执行SQL语句和浏览查询的结果集的接口. QSqlQueryModel和QSqlTableModel类提供了一个用于访问数据库的高级接口,这将在下一节介绍.如果你不熟 ...
- Eat that Frog
Eat that Frog,中文翻译过来就是“吃掉那只青蛙”.不过这里并不是讨论怎么去吃青蛙,而是一种高效的方法. Eat that Frog是Brian Tracy写的一本书(推荐阅读).这是一个很 ...
- 火狐flash插件
1.解压缩文件: tar -xzvf ***.tar.gz 会解出一个文件:libflashplayer.so 和一个目录 usr 2.将文件libflashplayer.so 拷贝到目录 /us ...
- poj 2342 Anniversary party 树形DP入门
题目链接:http://poj.org/problem?id=2342 题意:一家公司有1 <= N <= 6 000个职工,现要组织一些职工参加晚会,要求每个职工和其顶头上司不能同时参加 ...
- 用最直白的语言告诉你,hadoop是什么?
hadoop应历史之潮流,随着理论探索.科学技术试验的不断开展,hadoop终于2006年问世,惊天地泣鬼神! hadoop雏形开始于2002年的Apache的Nutch,Nutch是一个开源Java ...