zoukankan      html  css  js  c++  java
  • [POJ1054] The Troublesome Frog

    题意:有一块r×c的田地,夜晚有一些调皮的青蛙喜欢把田地里的水稻踩扁,于是留下了一串脚印,对于一串脚印,这串脚需满足:1、脚印印在一条直线上;2、使得青蛙是从田地外的一侧;3、脚印数大于等于3求最长的脚印串。

    题解:

    暴枚+剪纸

    排序,枚举两个点,得出跳跃方向和单次长度,暴力跳第二个点

    剪纸:如果第一个点不是从外面跳进来的就直接continue

    #include<iostream>
    #include<cstdio>
    #include<cstdlib>
    #include<cstring>
    #include<algorithm>
    #include<cmath>
    #define ll long long
    using namespace std;
    
    const int N = 5010;
    
    int ans,g[N][N];
    
    struct Node {
      int x,y;
      bool operator < (const Node a) const {
        return x==a.x?y<a.y:x<a.x;
      }
    }p[N];
    
    int gi() {
      int x=0,o=1; char ch=getchar();
      while(ch!='-' && (ch<'0' || ch>'9')) ch=getchar();
      if(ch=='-') o=-1,ch=getchar();
      while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
      return o*x;
    }
    
    int main() {
      int r=gi(),c=gi(),n=gi();
      for(int i=1; i<=n; i++) {
        p[i].x=gi(),p[i].y=gi();
        g[p[i].x][p[i].y]=1;
      }
      sort(p+1,p+n+1);
      for(int i=1; i<=n; i++)
        for(int j=i+1; j<=n; j++) {
          int dx=p[j].x-p[i].x,dy=p[j].y-p[i].y,res=0,x,y;
          if(p[i].x-dx>=1 && p[i].x-dx<=r && p[i].y-dy>=1 && p[i].y-dy<=c) continue;
          x=p[j].x+dx,y=p[j].y+dy;
          while(x>=1 && x<=r && y>=1 && y<=c) {
    	if(!g[x][y]) {res=0;break;}
    	else res++,x+=dx,y+=dy;
          }
          ans=max(ans,res);
        }
      if(ans) printf("%d", ans+2);
      else puts("0");
      return 0;
    }
    
  • 相关阅读:
    GDB+QEMU调试内核模块(实践篇)
    排序算法的python实现
    Linux命令行相关
    操作系统与网络
    计算机组成原理
    有了自己的技术博客
    if 和 if else
    十效率换算成十六进制
    <<左移 >>右移 >>>无符号右移 &与运算 |或运算 ^异或运算 ~反码
    // &与 // |或 // ^异或 // !非 // &&短路 // ||短路
  • 原文地址:https://www.cnblogs.com/HLXZZ/p/7513292.html
Copyright © 2011-2022 走看看