社区讨论
大常数 废 用流 跪求优化QwQ
P3705[SDOI2017] 新生舞会参与者 9已保存回复 38
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 38 条
- 当前快照
- 1 份
- 快照标识符
- @mi7dl1h4
- 此快照首次捕获于
- 2025/11/20 19:56 4 个月前
- 此快照最后确认于
- 2025/11/20 23:44 4 个月前
评测记录
第六个点嫌我丑QwQ
CPP// luogu-judger-enable-o2
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#define inf 1e5
#define eps 1e-6
#define mid (l+r)/2
using namespace std;
queue<int> Q;
struct node{
int x,y,c,next;
double d;
}a[30010];
int n,len=0,st,ed;
int last[210],last2[210];
double b1[110][110],b2[110][110],h[210];
void ins(int x,int y,int c,double d)
{
a[++len].y=y;a[len].c=c;a[len].d=d;
a[len].next=last[x];last[x]=len;
a[++len].y=x;a[len].c=0;a[len].d=-d;
a[len].next=last[y];last[y]=len;
}
bool bfs()
{
for(int i=st;i<=ed;i++) a[i].x=-1,h[i]=inf;
h[st]=0.0;
Q.push(st);
while(!Q.empty())
{
int x=Q.front();Q.pop();
for(int i=last[x];i;i=a[i].next)
{
int y=a[i].y;
if(a[i].c && h[y]>h[x]+a[i].d)
{
h[y]=h[x]+a[i].d;
a[y].x=x;last2[y]=i;
Q.push(y);
}
}
}
if(a[ed].x!=-1) return true;
return false;
}
double dfs()
{
double ans=0;
while(bfs())
{
int tot=inf;
for(int i=ed;i!=st;i=a[i].x) tot=min(tot,a[last2[i]].c);
ans+=tot*h[ed];
for(int i=ed;i!=st;i=a[i].x) a[last2[i]].c-=tot,a[last2[i]^1].c+=tot;
}
return ans;
}
bool check(double x)
{
memset(last,0,sizeof(last));
len=1;
for(int i=1;i<=n;i++) ins(st,i,1,0);
for(int i=1;i<=n;i++) ins(i+n,ed,1,0);
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++) ins(i,j+n,1,x*b2[i][j]-b1[i][j]);
if(dfs()<0) return true;
return false;
}
int main()
{
scanf("%d",&n);st=0;ed=2*n+1;
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++) scanf("%lf",&b1[i][j]);
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++) scanf("%lf",&b2[i][j]);
double l=0.0,r=10000000.0;
while(l<=r)
{
if(check(mid)) l=mid+eps;
else r=mid-eps;
}
printf("%.6lf",mid);
return 0;
}
回复
共 38 条回复,欢迎继续交流。
正在加载回复...