• poj1054 The Troublesome Frog 瞎搞。


    连接:http://poj.org/problem?id=1054

    题意:就是一个格子里一条线上最长有几个青蛙(青蛙间隔相同)~。但是其实青蛙的起点重点必须是在外面。

    直接写一个搜就是。

     1 #include <stdio.h>
     2 #include <string.h>
     3 #include <iostream>
     4 #include <algorithm>
     5 #include <stdlib.h>
     6 #include <vector>
     7 #include <queue>
     8 #include <stack>
     9 #define loop(s,i,n) for(i = s;i < n;i++)
    10 #define cl(a,b) memset(a,b,sizeof(a))
    11 using namespace std;
    12 int map[5005][5005];
    13 int r,c,n;
    14 struct node
    15 {
    16     int x,y;
    17 }p[50005];
    18 int cmp( struct node a, struct node b)
    19 {
    20     if(a.x == b.x)
    21     return a.y < b.y;
    22     return a.x < b.x;
    23 }
    24 int judge(int x,int y)
    25 {
    26     if(x >= 1 && x <= r && y >= 1&&y <= c)
    27     return 1;
    28 
    29     return 0;
    30 
    31 }
    32 int find(struct node tmp,int dx,int dy)
    33 {
    34 
    35     int ans = 2;
    36 
    37     int leap =1;
    38     while(judge(tmp.x+dx,tmp.y+dy))
    39     {
    40         if(map[tmp.x+dx][tmp.y+dy])
    41         {
    42             tmp.x+= dx,tmp.y += dy;
    43             ans++;
    44         }
    45         else
    46         {
    47             leap = 0;
    48             break;
    49         }
    50     }
    51     if(leap)
    52     return ans;
    53     return 0;
    54 }
    55 int main()
    56 {
    57     while(~scanf("%d %d",&r,&c))
    58     {
    59         int i,j;
    60         scanf("%d",&n);
    61 
    62         cl(map,0);
    63         for(i = 1;i <= n;i++)
    64         scanf("%d %d",&p[i].x,&p[i].y),map[p[i].x][p[i].y] = 1;
    65 
    66         sort(p+1,p+n+1,cmp);
    67         int ans = 0;
    68         for(i = 1;i <= n;i++)
    69         {
    70 
    71             for(j = i+1;j <= n;j++)
    72             {
    73 
    74                 int dx,dy;
    75                 dx = p[j].x-p[i].x;
    76                 dy = p[j].y-p[i].y;
    77                 struct node tmp;
    78                 tmp = p[j];
    79                 if(judge(p[i].x-dx,p[i].y-dy))
    80                 continue;
    81                 int cnt = find(tmp,dx,dy);
    82 
    83                 if(ans < cnt)
    84                 ans = cnt;
    85 
    86             }
    87         }
    88         if(ans < 3)
    89         puts("0");
    90         else
    91         printf("%d
    ",ans);
    92     }
    93     return 0;
    94 }
    View Code
  • 相关阅读:
    docker部署数据库
    JAVA 删除Map中元素(JDK8)
    Docker 学习记录基于Linux
    Liunx 操作命令学习记录
    NACOS 认识和学习
    SpringCloud 学习及其相关组件的认识
    springBoot 配置文件的优先级
    配置redisTemplate的序列化
    springBoot 使用测试类报错
    注解反射的认识
  • 原文地址:https://www.cnblogs.com/0803yijia/p/3296778.html
Copyright © 2020-2023  润新知