当前位置:网站首页>洛谷P1378 油滴扩展 题解
洛谷P1378 油滴扩展 题解
2022-06-21 20:13:00 【q779】
洛谷P1378 油滴扩展 题解
题目链接:P1378 油滴扩展
题意:
在一个长方形框子里,最多有 N N N 个相异的点,在其中任何一个点上放一个很小的油滴,那么这个油滴会一直扩展,直到接触到其他油滴或者框子的边界。必须等一个油滴扩展完毕才能放置下一个油滴。那么应该按照怎样的顺序在这 N N N 个点上放置油滴,才能使放置完毕后所有油滴占据的总体积最大呢?(不同的油滴不会相互融合)
注:圆的面积公式 V = π r 2 V = \pi r^2 V=πr2,其中 r r r 为圆的半径。
对于 100 % 100\% 100% 的数据, 1 ≤ N ≤ 6 1 \le N \le 6 1≤N≤6,坐标范围在 [ − 1000 , 1000 ] [-1000, 1000] [−1000,1000] 内。
数据范围告诉我们这就是一道暴搜题
枚举油滴扩展的顺序,然后和已经扩散好的油滴算一下距离
注意距离可能为负,此时新油滴在某油滴内部,此时认为 r = 0 r=0 r=0 即可
最后的答案就是总面积减去油滴面积并
时间复杂度 O ( n × n ! ) O(n\times n!) O(n×n!)
代码:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iomanip>
using namespace std;
#define int long long
#define INF 0x3f3f3f3f3f3f3f3f
#define N (int)(15)
const double pi = 3.14159265354;
int n,vis[N];
double xa,ya,xb,yb,x[N],y[N],S,mx,r[N];
#define pf(x) ((x)*(x))
double dis(int i,int j)
{
return sqrt(pf(x[i]-x[j])+pf(y[i]-y[j]));}
double cal(int i)
{
double l1=min(abs(x[i]-xa),abs(x[i]-xb));
double l2=min(abs(y[i]-ya),abs(y[i]-yb));
double res=min(l1,l2);
for(int j=1; j<=n; j++)
if(i!=j&&vis[j])
{
double d=dis(i,j);
res=fmin(res,max(d-r[j],0.0));
}
return res;
}
void dfs(int k,double sum)
{
if(k>n)
{
mx=max(mx,sum);
return;
}
for(int i=1; i<=n; i++)
{
if(!vis[i])
{
r[i]=cal(i);
vis[i]=1;
dfs(k+1,sum+r[i]*r[i]*pi);
vis[i]=0;
}
}
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
// freopen("check.in","r",stdin);
// freopen("check.out","w",stdout);
cin >> n >> xa >> ya >> xb >> yb;
S=abs((xa-xb)*(ya-yb));
for(int i=1; i<=n; i++)
cin >> x[i] >> y[i];
dfs(1,0);
cout << fixed << setprecision(0);
cout << S-mx << endl;
return 0;
}
转载请说明出处
边栏推荐
- 挖财赠送的证券账户安全吗?可以开户吗?
- Prototype extension: implementing object inheritance
- 面了十多家实习岗位失败的实习面试经历总结
- 杰理之,提示芯片信 息不匹配,错误代号 10 的处理方法【篇】
- Abbkine细胞周期染色试剂盒特色和实验建议
- 电子招标采购商城系统:优化传统采购业务,提速企业数字化升级
- solidity实现智能合约教程(4)-ERC1155合约
- There is no sound solution to the loopback when jerryzhi launches Bluetooth [chapter]
- Introduction to security encryption
- JS异步的执行顺序是什么
猜你喜欢

Intelij idea efficient skills (II)

British teddy bear joins the pubg mobile game

New energy industry commercial procurement collaboration system: enable new energy industry procurement business and enhance industrial collaboration

Guangdong CDC reminds: the summer vacation is coming, so the returned college students can "return home" safely

全屋智能家居品牌“智汀科技”有体验中心?
![Jerry wants to keep both earphones output stereo after pairing them [chapter]](/img/47/c3b09561e87a58226fa232e30747d7.png)
Jerry wants to keep both earphones output stereo after pairing them [chapter]

Mendeley installation, configuration and use

opencvsharp阈值分割threshold函数的ThresholdTypes

Abbkine细胞周期染色试剂盒特色和实验建议

Qx2308 high efficiency PFM Synchronous Boost dc/dc converter
随机推荐
P6758 [BalticOI2013] Vim
M3608 boost IC chip high efficiency 2.6a boost dc/dc converter
JS异步的执行顺序是什么
Go language unit test basics from getting started to giving up
Data types in JS (basic)
Introduction to security encryption
数商云纸业集团供应商管理系统:推进企业信息化建设,全面提升供应商管理效率
prototype扩展:实现对象继承
龙蜥社区成立云原生SIG,引入3大核心技术
怎样有效率地进行外文文献检索?
对“XXX::Invoke”类型的已垃圾回收委托进行了回调。这可能会导致应用程序崩溃、损坏和数据丢失。向非托管代码传递委托时,托管应用程序必须让这些委托保持活动状态,直到确信不会再次调用它们
New energy industry commercial procurement collaboration system: enable new energy industry procurement business and enhance industrial collaboration
InteliJ-IDEA-高效技巧(一)
杰理之外挂收音注意事项【篇】
Synchronous Boost dc/dc converter fs3400 synchronous SOT23-6 small current 500mA boost IC
GAMES101作业7-多线程提速实现步骤详解
Jerizhi, processing method for prompting chip information mismatch and error code 10 [chapter]
处理订单业务多面手,订货管理系统实现企业订货库存统一管理
Overriding Overloading final
Jerry wants to keep both earphones output stereo after pairing them [chapter]