bzoj 1193
大范围贪心, 小范围暴力。。。。。
1 #include<bits/stdc++.h> 2 #define LL long long 3 #define fi first 4 #define se second 5 #define mk make_pair 6 #define pii pair<int,int> 7 #define piii pair<int, pair<int,int>> 8 9 10 using namespace std; 11 12 const int N=20+7; 13 const int M=1e4+7; 14 const int inf=0x3f3f3f3f; 15 const LL INF=0x3f3f3f3f3f3f3f3f; 16 const int mod=1e9 + 7; 17 18 int n, xp, yp, xs, ys, dx[] = {1, 1, 2, 2, -1, -1, -2, -2}, dy[] = {2, -2, 1, -1, 2, -2, 1, -1}, d[100][100]; 19 bool check(int x, int y) { 20 if(x < 0 || x >= 30) return false; 21 if(y < 0 || y >= 30) return false; 22 if(d[x][y] != inf) return false; 23 return true; 24 } 25 26 void bfs() { 27 queue<pii> que; 28 que.push(mk(1, 1)); 29 d[1][1] = 0; 30 while(!que.empty()) { 31 pii u = que.front(); que.pop(); 32 for(int i = 0; i < 8; i++) { 33 pii v = mk(u.fi + dx[i], u.se + dy[i]); 34 if(check(v.fi, v.se)) { 35 d[v.fi][v.se] = d[u.fi][u.se] + 1; 36 que.push(v); 37 } 38 } 39 } 40 } 41 42 int main() { 43 memset(d, inf, sizeof(d)); 44 scanf("%d%d%d%d", &xp, &yp, &xs, &ys); 45 int x = abs(xp - xs); 46 int y = abs(yp - ys); 47 int ans = 0; 48 bfs(); 49 while(x >= 20 || y >= 20) { 50 if(x < y) swap(x, y); 51 x -= 2, y -= 1; 52 x = abs(x), y = abs(y); 53 ans++; 54 } 55 printf("%d\n", ans + d[x + 1][y + 1]); 56 return 0; 57 } 58 /* 59 */