1. 程式人生 > >百練2812:惱人的青蛙

百練2812:惱人的青蛙

style using gif ret 青春 stream rac ring its

傳送門: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

百練2812:惱人的青蛙