# 油滴扩展_洛谷1378_搜索

2017-01-13 11:33:56来源:CSDN作者:jpwang8人点击

## 题解

n只有6，直接无脑dfs，注意判断点在盒子外的情况

## Code

``#include <stdio.h>#include <string.h>#include <math.h>#define rep(i, a, b) for (int i = a; i <= b; i++)#define fill(x, t) memset(x, t, sizeof(x))#define db double#define INF 0x3f3f3f3f#define PI 3.141592653#define N 7using namespace std;struct rec{int u, d, l, r;}r;struct cir{int x, y; db r;}c[N];int vis[N];db ans = INF;inline int read(){    int x = 0, v = 1;    char ch = getchar();    while (ch < '0' || ch > '9'){        if (ch == '-'){            v = -1;        }        ch = getchar();    }    while (ch <= '9' && ch >= '0'){        x = x * 10 + ch - '0';        ch = getchar();    }    return x * v;}inline db dist(cir a, cir b){    return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));}inline db cal(db R){    return PI * R * R;}inline db max(db x, db y){    return x>y?x:y;}inline db min(db x, db y){    return x<y?x:y;}inline int dfs(int dep, db S, rec rc, int n){    if (dep == n + 1){        ans = min(ans, S);        return 0;    }    rep(i, 1, n){        if (!vis[i]){            db R = INF;            rep(j, 1, n){                if (vis[j]){                    R = min(R, dist(c[i], c[j]) - c[j].r);                }            }            R = min(R, c[i].y - rc.d);            R = min(R, rc.u - c[i].y);            R = min(R, c[i].x - rc.l);            R = min(R, rc.r - c[i].x);            if (R > 0){                vis[i] = true;                c[i].r = R;                dfs(dep + 1, S - cal(R), rc, n);                c[i].r = 0;                vis[i] = false;            }else{                dfs(dep + 1, S, rc, n);            }        }    }}int main(void){    int n = read();    int x1 = read(), y1 = read(), x2 = read(), y2 = read();    r = (rec){max(y1, y2), min(y1, y2), min(x1, x2), max(x1, x2)};    rep(i, 1, n){        c[i] = (cir){read(), read(), 0};    }    dfs(1, (r.u-r.d) * (r.r-r.l), r, n);    printf("%d/n",int(ans + 0.5));    return 0;}``