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 ...
随机推荐
- 规则引擎ILog和CKRule的对比
IBM™ WebSphere™ ILOG是业界最有影响力的业务规则商业软件,它提供了最好的业务规则管理系统,在Java领域更是有广泛的成功案例.网上关于ILOG的技术资料非常多,大家都比较了解ILOG ...
- 基础之ThreadStatic
public class Bean { public Bean() { } public static String Current { get { if (guid == null) guid = ...
- “Assign Random Colors” is not working in 3ds Max 2015
Go to Customize -> Preferences…-> General (tab) Uncheck “Default to By Layer for New Nodes”
- CLR has been unable to transition from COM context for 60 seconds
Original link: http://blog.wpfwonderland.com/2007/08/16/clr-has-been-unable-to-transition-from-com-c ...
- Xml通用操作类
using System; using System.Collections.Generic; using System.IO; using System.Text; using System.Xml ...
- QtSQL学习笔记(4)- 使用SQL Model类
除了QSqlQuery,Qt提供了3个高级类用于访问数据库.这些类是QSqlQueryModel.QSqlTableModel和QSqlRelationalTableModel. 这些类是由QAbst ...
- RX学习笔记:JavaScript数组操作
RX学习笔记:JavaScript数组操作 2016-07-03 增删元素 unshift() 在数组开关添加元素 array.unshift("value"); array.un ...
- JavaScript 对象的几种创建方法
/** * Created by 2016 on 2016/6/4. */ function Box(){ var obj = new obj(); obj.name = "Lee" ...
- iOS应用数据存储的常用方式
iOS应用 数据存储的常用方式 XML属性列表 plist Preference 偏好设置 NSKeyedArchiver 归档 Core Data SQLite3 应用沙盒: Layer: ...
- hdu 5626 Clarke and points 数学推理
Clarke and points Problem Description The Manhattan Distance between point A(XA,YA) and B(XB,YB) i ...