社区讨论
灵异事件
P1378油滴扩展参与者 7已保存回复 9
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 9 条
- 当前快照
- 1 份
- 快照标识符
- @mhj072ax
- 此快照首次捕获于
- 2025/11/03 18:34 4 个月前
- 此快照最后确认于
- 2025/11/03 18:34 4 个月前
为什么取名x1,x2,y1,y2会Compile Error
CPP#include <iostream>
#include <cmath>
using namespace std;
const int N = 10;
const double PI = 3.1415926535;
struct node{
double x, y;
}a[N];
bool vis[N];
double x1, y1, x2, y2;
double ans;
double r[N];
int n;
double calc(int i){ // 求半径
//到边界
double s1 = min(abs(a[i].x - x1), abs(a[i].x - x2));
double s2 = min(abs(a[i].y - y1), abs(a[i].y - y2));
double fans = min(s1, s2);
//到油滴
for(int j = 1; j <= n; j++){
if(i != j && vis[j]){
double finalans=sqrt((a[i].x-a[j].x)*(a[i].x-a[j].x)+(a[i].y-a[j].y)*(a[i].y-a[j].y));
fans = min(fans, max(finalans - r[j], 0.0));
}
}
return fans;
}
void dfs(int dep, double sum){
if(dep > n){
ans = max(ans, sum);
return ;
}
for(int i = 1; i <= n; i++){
if(!vis[i]){
r[i] = calc(i);
vis[i] = 1;
dfs(dep+1, sum + r[i] * r[i] * PI);
vis[i] = 0;
}
}
}
int main(){
double ss;
cin >> n;
cin >> x1 >> y1 >> x2 >> y2;
ss = abs(x1 - x2) * abs(y1 - y2);
//cout << ss << endl;
for(int i = 1; i <= n; i++)
cin >> a[i].x >> a[i].y;
dfs(1, 0);
cout << int(ss - ans + 0.5) << endl;
return 0;
}
回复
共 9 条回复,欢迎继续交流。
正在加载回复...