• 百练2812:恼人的青蛙


    传送门:http://bailian.openjudge.cn/practice/2812/

    【题解】

    垃圾题目毁我青春。

    暴力枚举两个点,判断是否成立。

    瞎jb判一判,剪剪枝就过了。

    大概就是排序后如果当前x+dx已经大于n了就break

    (听说会快很多(并没有))

    我怎么这么傻逼啊:反正只有一条路径,只要找头两个即可,那么会省去很多时间。

    # include <stdio.h>
    # include <string.h>
    # include <iostream>
    # include <algorithm>
    // # include <bits/stdc++.h>
    
    using namespace std;
    
    typedef long long ll;
    typedef long double ld;
    typedef unsigned long long ull;
    const int M = 5000 + 10;
    const int mod = 1e9+7;
    
    # define RG register
    # define ST static
    
    int n, m, K, ans = 0;
    struct point {
        int x, y;
        point() {}
        point(int x, int y) : x(x), y(y) {}
        friend bool operator == (point a, point b) {
            return a.x == b.x && a.y == b.y;
        }
        friend bool operator != (point a, point b) {
            return !(a==b);
        }
        friend bool operator < (point a, point b) {
            return a.x < b.x || (a.x == b.x && a.y < b.y);
        }
        friend bool operator > (point a, point b) {
            return a.x > b.x || (a.x == b.x && a.y > b.y);
        }
    }p[M];
    
    bool mp[M][M];
    
    inline bool in(int x, int y) {
        return 1 <= x && x <= n && 1 <= y && y <= m;
    }
    
    int main() {
        point cur;
        cin >> n >> m >> K;
        for (int i=1; i<=K; ++i) {
            scanf("%d%d", &p[i].x, &p[i].y);
            mp[p[i].x][p[i].y] = 1;
        }
        sort(p+1, p+K+1);
        for (int i=1; i<=K; ++i)
            for (int j=i+1, t; j<=K; ++j) {
                int dx = p[j].x - p[i].x, dy = p[j].y - p[i].y;
                if(p[j].x + dx < 1 || p[j].x + dx > n) break;
                if(in(p[i].x - dx, p[i].y - dy)) continue;
                if(p[j].y + dy < 1 || p[j].y + dy > m) continue;
                t = 2; cur = p[j];
                while(in(cur.x + dx, cur.y + dy) && mp[cur.x + dx][cur.y + dy]) {
                    cur = point(cur.x + dx, cur.y + dy);
                    ++t;
                }
                if(in(cur.x + dx, cur.y + dy)) continue;
                if(t != 2) ans = max(ans, t);    
            }
        cout << ans << endl;
        return 0;
    }
    View Code
  • 相关阅读:
    OpenMP笔记(一)
    Ubuntu16.04编译OpenCV3.4.7
    Ubuntu16.04编译tensorflow的C++接口
    win10编译tensorflow C++接口
    Qt5学习笔记(1)-环境配置(win+64bit+VS2013)
    Qt creator中配置opencv win7 64bit
    MYSQL其他常用函数
    MySQL 8.0中的新增功能
    MySQL中的JSON函数(三)修改JSON的函数
    MySQL中的JSON函数(二)查询JSON函数
  • 原文地址:https://www.cnblogs.com/galaxies/p/bailian2812.html
Copyright © 2020-2023  润新知