油滴扩展_洛谷1378_搜索

66 篇文章 0 订阅

题目描述


在一个长方形框子里,最多有N(0≤N≤6)个相异的点,在其中任何一个点上放一个很小的油滴,那么这个油滴会一直扩展,直到接触到其他油滴或者框子的边界。必须等一个油滴扩展完毕才能放置下一个油滴。那么应该按照怎样的顺序在这N个点上放置油滴,才能使放置完毕后所有油滴占据的总体积最大呢?(不同的油滴不会相互融合)

注:圆的面积公式V=pi*r*r,其中r为圆的半径。

输入格式:


第1行一个整数N。

第2行为长方形边框一个顶点及其对角顶点的坐标,x,y,x’,y’。

接下去N行,每行两个整数xi,yi,表示盒子的N个点的坐标。

以上所有的数据都在[-1000,1000]内。

输出格式:


一行,一个整数,长方形盒子剩余的最小空间(结果四舍五入输出)

题解


题目满是屮点,不想说了
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 7
using 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;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值