zoukankan      html  css  js  c++  java
  • 百练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
  • 相关阅读:
    长沙市资讯新闻汇总
    PC端页面同比例缩放
    操作系统之进程
    开发中遇到的一些mongoose的问题
    支持字母数字下划线和中文的正则
    将redis作为windows服务安装
    express中的会话存储方式
    getServletContext()接口解析(收藏)
    在本地计算机无法启动MYSQL服务错误1067进程意外终止
    css浮动中避免包含元素高度为0的4种解决方法
  • 原文地址:https://www.cnblogs.com/galaxies/p/bailian2812.html
Copyright © 2011-2022 走看看